c语言 输入一个三行四列的二维数组 求各行各列的平均值

2024-11-23 00:19:49
推荐回答(1个)
回答1:

#include

void main(){
int source[3][4],i,j:
float avg;
for(i=0;i<3;i++){
avg=0;
for(j=0;j<4;j++){
scanf("%d",&source[i][j]);
avg+=source[i][j];
}
printf("stu%d avgsource:%f\t",i,avg/4);
}
printf("\n");
for(i=0;i<4;i++){
avg=0;
for(j=0;j<3;j++)
avg=source[j][i];
printf("class%d avgsource:%f\t",i,avg/3);

}

}