#include
#include
int main()
{
int i=0,j=0,total=0;
float avr=0;
int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
for (i=0;i<3;i++)
{
total=0;
for (j=0;j<3;j++)
{
total +=a[i][j];
}
avr = (float)(total/3.0);
printf("sum[%d] aver[%.2f]\n",total,avr);
}
return 0;
}
sum[6] aver[2.00]
sum[15] aver[5.00]
sum[24] aver[8.00]
Press any key to continue
#include
void main()
{
int arr[3][4] = {0};
int i = 0, j = 0, add=0;
for(i=0; i<3; i++)
{
for(j =0; j<4; j++)
{
scanf("%d", &arr[i][j]);
}
}
#if 0
//键盘输入求数组每一行的平均值
for(i=0; i<3; i++)
{
int sum=0;
for(j=0; j<4; j++)
{
sum += arr[i][j];
}
printf("第%d行的平均值%d\n", i, sum/4 );
}
#endif
//键盘输入求每一列的平均值
for(j=0; j<4; j++)
{
int sum=0;
for(i=0; i<3; i++)
{
sum += arr[i][j];
}
printf("第%d列的平均值%d\n", j, sum/3 );
}
}