#include<stdio.h>
void main()
{
int grade[5][5] = {
{80,88,93},
{76,74,81},
{58,66,64},
{63,73,71},
{77,92,90}};
int i , j , sum1,sum2,sum3,sum4,sum5;
float ave[8];
for (i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
printf("%-3d",grade[i][j]);
}
printf("\n");
}
sum1 = grade[0][0] + grade[0][1] + grade[0][2];
ave[0] = (float)sum1/3;
sum2 = grade[1][0] + grade[1][1] + grade[1][2];
ave[1] = (float)sum2/3;
sum3 = grade[2][0] + grade[2][1] + grade[2][2];
ave[2] = (float)sum3/3;
sum4 = grade[3][0] + grade[3][1] + grade[3][2];
ave[3] = (float)sum4/3;
sum5 = grade[4][0] + grade[4][1] + grade[4][2];
ave[4] = (float)sum5/3;
printf("The first student's average is ===>%3.2f \n",ave[0]);
printf("The second student's average is ===>%3.2f \n",ave[1]);
printf("The third student's average is ===>%3.2f \n",ave[2]);
printf("The fourth student's average is ===>%3.2f \n",ave[3]);
printf("The fifth student's average is ===>%3.2f \n",ave[4]);
{
int sum6,sum7,sum8;
sum6 = grade[0][0] + grade[1][0] + grade[2][0] + grade[3][0] + grade[4][0];
ave[5] = (float)sum6/5;
sum7 = grade[0][1] + grade[1][1] + grade[2][1] + grade[3][1] + grade[4][1];
ave[6] = (float)sum7/5;
sum8 = grade[0][2] + grade[1][2] + grade[2][2] + grade[3][2] +grade[4][2];
ave[7] = (float)sum8/5;
printf("The all class's Math average is ===>%3.2f \n",ave[5]);
printf("The all class's English average is ===>%3.2f \n",ave[6]);
printf("The all class's Electronics average is ===>%3.2f\n",ave[7]);
}
{
int i,j,tmp;
int num[5];
for(i=0;i<5;i++)
num[i]=ave[i];
for(i=0;i<2;i++)
{
for( j=0;j<4;j++)
if (num[j]>num[j+1])
{
tmp = num[j];
num[j]=num[j+1];
num[j+1] = tmp;
}
printf("\2:loop %d ",i);
for(j=0;j<5;j++)
printf("%4d",num[j]);
printf("\n");
}
printf("\2:排名 %d %d %d %d %d \n",5,4,3,2,1);
}
}
可以了吧.......不懂再來問
|