//Write a prog to read data of 30 students for four subjects. total marks obtained, student with highest marks in each subject and student with highest marks.
#include<stdio.h>
#define SIZE 30
struct stu { //stu for student
char name[30];
int rollno;
int sub[4];
};
void main() {
int i, j, max, count, total, n, a[SIZE], ni; // n for number of students
struct stu st[SIZE];
clrscr();
printf("Enter Number of students: "); // for eg: 2 students
scanf("%d", &n);
// loop to print 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);
}
//loop to print ith student's jth subject
for (i = 0; i < n; i++) {
for (j = 0; j <= 4; 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 < 4; j++) {
total = total + st[i].sub[j];
}
printf("\nTotal marks obtained by student %s are %d\n", 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 < 4; 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();
}
#include<stdio.h>
#define SIZE 30
struct stu { //stu for student
char name[30];
int rollno;
int sub[4];
};
void main() {
int i, j, max, count, total, n, a[SIZE], ni; // n for number of students
struct stu st[SIZE];
clrscr();
printf("Enter Number of students: "); // for eg: 2 students
scanf("%d", &n);
// loop to print 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);
}
//loop to print ith student's jth subject
for (i = 0; i < n; i++) {
for (j = 0; j <= 4; 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 < 4; j++) {
total = total + st[i].sub[j];
}
printf("\nTotal marks obtained by student %s are %d\n", 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 < 4; 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();
}