Problem Statement:
Write a c program to read and print details of 50 students using structure.
Solutions:
Below we have shared the solution to read and print details of 50 students using structure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include<stdio.h> #define SIZE 50 struct student { char name[30]; int rollno; int sub[3]; }; void main() { int i, j, max, count, total, n, a[SIZE], ni; struct student st[SIZE]; clrscr(); printf("Enter how many students: "); scanf("%d", &n); /* for loop to read the names and roll numbers*/ for (i = 0; i < n; i++) { printf("\nEnter name and roll number for student %d : ", i); scanf("%s", &st[i].name); scanf("%d", &st[i].rollno); } /* for loop to read ith student's jth subject*/ for (i = 0; i < n; i++) { for (j = 0; j <= 2; j++) { printf("\nEnter marks of student %d for subject %d : ", i, j); scanf("%d", &st[i].sub[j]); } } /* (i) for loop to calculate total marks obtained by each student*/ for (i = 0; i < n; i++) { total = 0; for (j = 0; j < 3; j++) { total = total + st[i].sub[j]; } printf("\nTotal marks obtained by student %s are %dn", st[i].name,total); a[i] = total; } /* (ii) 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 (i = 0; i < n; i++) { if (max < st[i].sub[j]) { max = st[i].sub[j]; ni = i; } } printf("\nStudent %s got maximum marks = %d in Subject : %d",st[ni].name, max, j); } max = 0; for (i = 0; i < n; i++) { if (max < a[i]) { max = a[i]; ni = i; } } printf("\n%s obtained the total highest marks.", st[ni].name); getch(); } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.