Student Marks Calculation
#include <stdio.h>
#define NUM_STUDENTS 3
#define NUM_SUBJECTS 3
// Define a structure for student details
struct Student {
int marks[NUM_SUBJECTS];
int totalMarks;
};
int main() {
struct Student students[NUM_STUDENTS] = {{0}, {0}, {0}};
// Read marks for each student and subject
for (int i = 0; i < NUM_STUDENTS; i++) {
printf("Enter marks for Student %d:\n", i + 1);
for (int j = 0; j < NUM_SUBJECTS; j++) {
printf("Enter marks for Subject %d: ", j + 1);
scanf("%d", &students[i].marks[j]);
students[i].totalMarks += students[i].marks[j];
}
}
// Print total marks scored by each student
printf("\nTotal marks scored by each student:\n");
for (int i = 0; i < NUM_STUDENTS; i++) {
printf("Student %d Total Marks: %d\n", i + 1, students[i].totalMarks);
}
// Calculate subject-wise total marks
int subjectTotal[NUM_SUBJECTS] = {0};
for (int i = 0; i < NUM_STUDENTS; i++) {
for (int j = 0; j < NUM_SUBJECTS; j++) {
subjectTotal[j] += students[i].marks[j];
}
}
// Print total marks scored in each subject
printf("\nTotal marks scored in each subject:\n");
for (int j = 0; j < NUM_SUBJECTS; j++) {
printf("Subject %d Total Marks: %d\n", j + 1, subjectTotal[j]);
}
return 0;
}