C Programming Code Examples C > Beginners Lab Assignments Code Examples C Program to Read and Print details of 50 Students using Structure C Program to Read and Print details of 50 Students using Structure The annual examination is conducted for 50 students for three subjects. Write a program to read the data and determine the following: Total marks obtained by each student. The highest marks in each subject and the Roll No. of the student who secured it. The student who obtained the highest total marks. #include<stdio.h> #define SIZE 50 struct student { char name[30]; int rollno; int sub[3]; }; void main() { int x, j, max, count, total, n, a[SIZE], nx; struct student st[SIZE]; clrscr(); printf("Enter how many students: "); scanf("%d", &n); /* for loop to read the names and roll numbers*/ for (x = 0; x < n; x++) { printf("\nEnter name and roll number for student %d : ", x); scanf("%s", &st[x].name); scanf("%d", &st[x].rollno); } /* for loop to read xth student's jth subject*/ for (x = 0; x < n; x++) { for (j = 0; j <= 2; j++) { printf("\nEnter marks of student %d for subject %d : ", x, j); scanf("%d", &st[x].sub[j]); } } /* (x) for loop to calculate total marks obtained by each student*/ for (x = 0; x < n; x++) { total = 0; for (j = 0; j < 3; j++) { total = total + st[x].sub[j]; } printf("\nTotal marks obtained by student %s are %dn", st[x].name,total); a[x] = total; } /* (xx) for loop to list out the student's roll numbers who have secured the highest marks in each subject */ /* roll number who secured the highest marks */ for (j = 0; j < 3; j++) { max = 0; for (x = 0; x < n; x++) { if (max < st[x].sub[j]) { max = st[x].sub[j]; nx = x; } } printf("\nStudent %s got maximum marks = %d in Subject : %d",st[nx].name, max, j); } max = 0; for (x = 0; x < n; x++) { if (max < a[x]) { max = a[x]; nx = x; } } printf("\n%s obtained the total highest marks.", st[nx].name); getch(); }