如何在知道矩阵大小的情况下找到矩阵 w/o 的最大值

How to find max of a matrix w/o knowing the size of it

变量“students”由用户提供,然后我必须在函数中使用它来查找矩阵的最大值。请注意,“学生”是矩阵的行,我必须使用它。 “学生”需要包含在函数的参数中。 更好的功能也不能正常工作,我不知道为什么。 这些是编译器消息:

警告:从不兼容的指针类型 [-Wincompatible-pointer-types] 传递 'better' 的参数 1 73 | int max = better(*成绩,学生);

注意:应为 'int **' 但参数的类型为 'int *' 5 | int 更好(int **pin,int 学生){

我还收到一条警告,用于比较函数 better() 中的整数指针

我输入的数字是 1 2 0 0 0 0 3 5 1 10 返回的最大值等于 2。

#include <stdio.h>
#define TESTS 5

int better(int **pin,int students){
    

    int max = 0;
    int k = 0;

    for(int i = 0; i < students; i++){
        
        for(int j = 0; j < TESTS; j++){
            
            
            if(*(pin + k) >= 0 && *(pin + k) <= 10){

                if(max < *(pin + k)){

                    max = *(pin + k);
                }
            }

            k++;
        }
    }
    return max;
}

int main(){

    int students;
    printf("Grades should always be a number between 0-10!\n\n");

    printf("Enter number of students: ");
    scanf("%d", &students);

    int grades[students][TESTS], value;
    

    for(int i = 0; i < students; i++){
        for(int j = 0; j < TESTS; j++){

        printf("Enter a value: ");
        scanf("%d", &value);
        if(value < 0){continue;}
        if(value > 10){continue;}
        grades[i][j] = value;

        }
    }

    for(int i = 0; i < students; i++){
        for(int j = 0; j < TESTS; j++){

        if(grades[i][j] < 0 || grades[i][j] > 10){
            grades[i][j] = 0;
        }

        }
    }

     for(int i = 0; i < students; i++){
         for(int j = 0; j < TESTS; j++){

         printf("%d ", grades[i][j]);

         }
         printf("\n");
     }

    int max = better(*grades,students);
    
    printf("\nmax of grades is: %d", max);

    return 0;
}

如果有人能帮助我,我将不胜感激!

#include <stdio.h>
#define TESTS 5

int better(int students, int grades[students][TESTS]){
    
    int max = 0;

    for(int i = 0; i < students; i++){
        
        for(int j = 0; j < TESTS; j++){
        
            if(max < grades[i][j]){
                max = grades[i][j];
            }

        }
    }
    return max;
}

int main(){

    int students;
    printf("Grades should always be a number between 0-10!\n\n");

    printf("Enter number of students: ");
    scanf("%d", &students);

    int grades[students][TESTS], value;
    

    for(int i = 0; i < students; i++){
        printf("Enter values for No.%d student:\n", i+1);
        for(int j = 0; j < TESTS; j++){

        printf("Enter a value: ");
        scanf("%d", &value);
        grades[i][j] = value;

        }
    }

    for(int i = 0; i < students; i++){
        for(int j = 0; j < TESTS; j++){

        if(grades[i][j] < 0 || grades[i][j] > 10){
            grades[i][j] = 0;
        }

        }
    }

    for(int i = 0; i < students; i++){
        for(int j = 0; j < TESTS; j++){

        printf("%d ", grades[i][j]);

        }
        printf("\n");
    }

    int MAX = better(students, grades);
    printf("Max grade is: %d", MAX);
    return 0;
}