用指针实现二维数组作为参数-求几个班级的平均成绩

二维数组作为参数传递时,一般都会用以下的这两种方式:

#include <stdio.h>

void average(float *p,int n);
void search(float (*p)[4],int n);

int main()
{
    float score[3][4]={{65,67,70,60},{80,87,90,81},{90,99,100,98}};
    average(*score,12);
    search(score,2);
    printf("**score is :%2.0f\n",**score) ;
    return 0;
}
void average(float *p,int n)
{
    float *p_end;
    float sum=0,aver;
    p_end=p+n-1;
    for(;p<=p_end;p++)
        sum+=*p;
    aver=sum/n;
    printf("average is %5.2f\n",aver);
}

void search(float (*p)[4],int n)
{
    int i;
    printf("The score of N0.%d student are:\n",n);
    for(i=0;i<4;i++)
        printf("%5.2f ",*(*(p+n)+i));
    printf("\n");
}


你可能感兴趣的:(c,二维数组,指针,参数传递)