回复 5楼 TonyDeng
我把整体代码发上来,帮我跑一下可以不,因为每该一步都会有新的错误。。导致我不知道怎么改了
#include<stdio.h>
double get_stu(double *stu,int cols,int rows);
double count_row(double *stu,int cols,int rows);
double count_col(double *stu,int cols,int rows);
double count_tot(double *stu,int cols,int rows);
double get_max(double *stu,int cols,int rows);
int main(void)
{
printf("enter any key to begin or 'q' to quit\n");
while(getchar()!='q')
{
printf("please enter the numbers\n");
double stu[3][5];
get_stu(*stu,5,3);
count_row(*stu,5,3);
count_col(*stu,5,3);
count_tot(*stu,5,3);
get_max(*stu,5,3);
while(getchar()!='\n')
{
continue;
}
printf("enter any key to begin or 'q' to quit\n");
}
printf("bye~~~!\n");
return 0;
}
double get_stu(double *stu,int cols,int rows)
{
int col,row;
for(row=0;row<rows;row++)
{
for(col=0;col<cols;col++)
{
printf("请输入第%d行第%d个数:\n",row+1,col+1);
scanf("%f",&stu[row][col]);
}
}
return 0;
}
double count_col(double *stu,int cols,int rows)
{
double num=0;
int row,col;
for(col=0;col<cols;col++)
{
num=0;
for(row=0;row<rows;row++)
{
num+=stu[row][col];
}
printf("第%d列的平均数:%f\n",col+1,num/rows);
}
return 0;
}
double count_row(double *stu,int cols,int rows)
{
double num=0;
int row,col;
for(row=0;row<rows;row++)
{
num=0;
for(col=0;col<cols;col++)
{
num+=stu[row][col];
}
printf("第%d个数集的平均数:%f\n",row+1,num/cols);
}
return 0;
}
double count_tot(double *stu,int cols,int rows)
{
double num=0;
int row,col;
for(row=0;row<rows;row++)
{
for(col=0;col<cols;col++)
{
num+=stu[row][col];
}
}
printf("所有数值平均数:%f\n",num/(cols*rows));
return 0;
}
double get_max(double *stu,int cols,int rows)
{
double max=0;
int row,col;
for(row=0;row<rows;row++)
{
for(col=0;col<cols;col++)
{
max=max<stu[row][col]?stu[row][col]:max;
}
}
printf("数组中最大的数是%f\n",max);
return 0;
}