Here's a fairly simple program that finds the max element of an 2d array grades and prints it out to the screen
#include <stdio.h>
const int t = 5;
int num_of_students;
int better(int grades[num_of_students][t], int num_of_students)
{
int i, k;
int max = grades[0][0];
for (i = 0; i < num_of_students; i++)
{
for (k = 0; k < t; k ++)
{
if (grades[i][k] > max)
{
max = grades[i][k];
}
}
}
return max;
}
int main(void)
{
int i, k;
printf("Give the number of students who took the test: ");
scanf("%i", &num_of_students);
int grades[num_of_students][t];
for (i = 0; i < num_of_students; i++)
{
printf("Student %i\n", i+1);
for (k = 0; k < t; k++)
{
printf("Give the score on test %i: ", k+1);
scanf("%i", &grades[i][k]);
while (grades[i][k] < 0 || grades[i][k] > 100)
{
printf("Not an acceptable score, try again %i: ", k+1);
scanf("%i", &grades[i][k]);
}
}
}
int max = better(grades[num_of_students][t], num_of_students);
printf("The best score is %i\n", max);
}
Yet when I'm trying to run the program the following errors pop up: test.c:47:45: warning: passing argument 1 of 'better' makes pointer from integer without a cast [-Wint-conversion] test.c:6:16: note: expected 'int (*)[(sizetype)t]' but argument is of type 'int'