实验六
#include <stdio.h>
double average(float a,float b,float c) {float d; d=(a+b+c)/3;return d;}
double average2(float a, float b,float c,float d,float e)
{float q; q=(a+b+c+d+e)/5; return q; }
int main() { int i,j,n; float a[5][3]; for(i=0;i<5;i++)
{printf("请输入%d个同学的\n",i+1); for(j=0;j<3;j++)
{printf("第%d门学科成绩:",j+1); scanf("%f",&a[i][j]);}}
printf("**********************\n");
printf("*每门学科各自平均成绩*\n");
for(i=0;i<5;i++){printf("*第%d科学科平均成绩 *\n",i+1);
if(average(a[i][0],a[i][1],a[i][2])<10)printf("*%f *\n",average(a[i][0],a[i][1],a[i][2]));
else if(average(a[i][0],a[i][1],a[i][2])<100)printf("*%f *\n",average(a[i][0],a[i][1],a[i][2])); else printf("*%f *\n",average(a[i][0],a[i][1],a[i][2]));} printf("*五名同学各自平均成绩*\n");
for(i=0;i<3;i++){ printf("*第%d名学生平均成绩 *\n",i+1);
if(average2(a[0][i],a[1][i],a[2][i],a[3][i],a[4][i])<10)printf("*%f *\n",average2(a[0][i],a[1][i],a[2][i],a[3][i],a[4][i]));
else if(average2(a[0][i],a[1][i],a[2][i],a[3][i],a[4][i])<100)printf("*%f *\n",average2(a[0][i],a[1][i],a[2][i],a[3][i],a[4][i]));
else if(average2(a[0][i],a[1][i],a[2][i],a[3][i],a[4][i])<1000)printf("*%f *\n",average2(a[0][i],a[1][i],a[2][i],a[3][i],a[4][i])); } printf("**********************\n");
return 0; }