Source Code
// 58. Program to store & display information (name, roll, marks) of N students using struct
// Arpan Das - CST 2nd Year (VOCLET)
#include <stdio.h>
//#include <conio.h>
void main () {
int n, i, j;
char *subjects[6] = {"Bengali", "English", "Mathematics", "Science", "History", "Geography"};
struct students {
char name[30];
int roll;
int marks[6];
};
//clrscr();
printf("\t\t..:: store & display information (name, roll, marks) of N students using struct ::..\n\n");
printf("Please enter value of N: ");
scanf("%d", &n);
struct students student[n];
for (i=0; i<n; i++) {
printf("\nEnter name of student#%d: ", i+1);
scanf("%s", student[i].name);
printf("\nEnter roll of student#%d: ", i+1);
scanf("%d", &student[i].roll);
printf("\nEnter marks of student#%d: ", i+1);
for (j=0; j<6; j++) {
printf("\n\t%s: ", subjects[j]);
scanf("%d", &student[i].marks[j]);
}
}
printf("\n_________________________\n");
for (i=0; i<n; i++) {
printf("\nName of student#%d: %s", i+1, student[i].name);
printf("\nRoll of student#%d: %d", i+1, student[i].roll);
printf("\nMarks of student#%d: ", i+1);
for (j=0; j<6; j++)
printf("\n\t%s: %d", subjects[j], student[i].marks[j]);
}
//getch();
}
Output
..:: store & display information (name, roll, marks) of N students using struct ::..
Please enter value of N: 3
Enter name of student#1: John
Enter roll of student#1: 101
Enter marks of student#1:
Bengali: 50
English: 60
Mathematics: 45
Science: 68
History: 25
Geography: 87
Enter name of student#2: Bob
Enter roll of student#2: 45
Enter marks of student#2:
Bengali: 87
English: 65
Mathematics: 23
Science: 89
History: 45
Geography: 56
Enter name of student#3: Alice
Enter roll of student#3: 78
Enter marks of student#3:
Bengali: 98
English: 65
Mathematics: 45
Science: 78
History: 57
Geography: 94
_________________________
Name of student#1: John
Roll of student#1: 101
Marks of student#1:
Bengali: 50
English: 60
Mathematics: 45
Science: 68
History: 25
Geography: 87
Name of student#2: Bob
Roll of student#2: 45
Marks of student#2:
Bengali: 87
English: 65
Mathematics: 23
Science: 89
History: 45
Geography: 56
Name of student#3: Alice
Roll of student#3: 78
Marks of student#3:
Bengali: 98
English: 65
Mathematics: 45
Science: 78
History: 57
Geography: 94