(b)Write a C program to create a structure to store name, rollnumber, address and course (BCA, MCA) of ten students. Use array of structure to display details of the students.

, , No Comments

 Store and Display Student Details Using Structure

#include <stdio.h>

// Create structure for student

struct Student {

    char name[50];

    int roll;

    char address[100];

    char course[10];

};

int main() {

    struct Student s[10];

    int i;


    // Get student details

    for(i = 0; i < 10; i++) {

        printf("\nEnter details of student %d:\n", i + 1);


        printf("Name: ");

        scanf(" %[^\n]", s[i].name);


        printf("Roll Number: ");

        scanf("%d", &s[i].roll);


        printf("Address: ");

        scanf(" %[^\n]", s[i].address);


        printf("Course (BCA/MCA): ");

        scanf(" %[^\n]", s[i].course);

    }


    // Show student details

    printf("\n--- Student Details ---\n");

    for(i = 0; i < 10; i++) {

        printf("\nStudent %d\n", i + 1);

        printf("Name   : %s\n", s[i].name);

        printf("Roll   : %d\n", s[i].roll);

        printf("Address: %s\n", s[i].address);

        printf("Course : %s\n", s[i].course);

    }


    return 0;

0 टिप्पणियाँ:

Post a Comment