Answer:
#include <stdio.h>
int MaxMark(int* arr, int size) {
int maxMark = 0;
if (size > 0) {
maxMark = arr[0];
}
for (int i = 0; i < size; i++) {
if (arr[i] > maxMark) {
maxMark = arr[i];
}
}
return maxMark;
}
int SumMarks(int* arr, int size) {
int sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
return sum;
}
float AvgMark(int* arr, int size) {
int sum = SumMarks(arr, size);
return (float)sum / size;
}
int main()
{
int student0[] = { 7, 5, 6, 9 };
int student1[] = { 3, 7, 7 };
int student2[] = { 2, 8, 6, 1, 6 };
int* marks[] = { student0, student1, student2 };
int nrMarks[] = { 4, 3, 5 };
int nrStudents = sizeof(marks) / sizeof(marks[0]);
for (int student = 0; student < nrStudents; student++) {
printf("Student %d: max=%d, sum=%d, avg=%.1f\n",
student,
MaxMark(marks[student], nrMarks[student]),
SumMarks(marks[student], nrMarks[student]),
AvgMark(marks[student], nrMarks[student]));
}
return 0;
}
Explanation:
Here is an example using a jagged array. Extend it to 15 students yourself. One weak spot is counting the number of marks, you have to keep it in sync with the array size. This is always a problem in C and would better be solved with a more dynamic data structure.
If you need the marks to be float, you can change the types.