看错了,Sorry```
[此贴子已经被作者于2006-12-7 22:53:22编辑过]
程序天下,C的亡魂。 偶``````来自地狱
//输入10个学生5门课的成绩,分别用函数求
//(1)每个学生平均分;
//(2)每门课的平均分.
#include <stdio.h>
#define ST 10
#define TC 5
int C_array[TC][ST];
void stu_each(void){
int i,j,sum;
for (i = 0;i < TC; ++i){
sum = 0;
for (j=0;j < ST; ++j){
sum +=C_array[i][j];
}
printf(" Student[%d] average is:%d\n",i,sum/ST);
}
}
void cou_each(void){
int i,j,sum;
for (i = 0;i < ST; ++i){
sum = 0;
for (j=0;j < TC; ++j){
sum +=C_array[j][i];
}
printf(" Course[%d] average is:%d\n",i,sum/TC);
}
}
int main(void){
int i,j;
for (i = 0;i < TC; ++i){
for (j=0;j < ST; ++j){
printf("Please Input Student[%d] Course[%d]:\n",i,j);
scanf("%d",&C_array[i][j]);
}
}
stu_each();
cou_each();
return 0;
}
以前写的。。。题目差不多。。。。
——————————————————————
#define M 10
#define N 5
float student_average(float (*p)[N],int stuno)/*求学生平均成绩*/
{ float sum=0;
int i;
for(i=0;i<N;i++)
sum=sum+*(*(p+stuno)+i);
return sum/N;
}
float course_average(float (*p)[N],int courseno)/*求每门课的平均成绩*/
{ float sum=0;
int i;
for(i=0;i<M;i++)
sum=sum+*(*(p+i)+courseno);
return sum/M;
}
void highest(float (*p)[N]) /*计算最高分*/
{ float most=0;
int i,j;
printf("Highest score:\n");
for(i=0;i<M;i++)
for(j=0;j<N;j++)
if(most<*(*(p+i)+j))
most=*(*(p+i)+j);
for(i=0;i<M;i++)
for(j=0;j<N;j++)
if(*(*(p+i)+j)==most)
printf("Highest score:%3.2f NO.%d course:%d\n",most,i+1,j+1);
}
float fangcha(float (*p)[N]) /*求方差*/
{ int i;
float result,sum1=0,sum2=0;
for(i=0;i<M;i++)
{sum1=sum1+student_average(p,i)*student_average(p,i);
sum2=sum2+student_average(p,i);
}
result=sum1/N-(sum2/N)*(sum2/N);
return result;
}
void input(float (*p)[N]) /*输入成绩*/
{ int i,j;
printf("Input the score:\n");
for(i=0;i<M;i++)
{printf("NO%d:",i+1);
for(j=0;j<N;j++)
scanf("%f",*(p+i)+j);
printf("\n");
}
}
void main()
{ float stu[M][N];
int i,j;
input(stu);
for(i=0;i<M;i++)
printf("the average score of NO%d is: %3.2f\n",i+1,student_average(stu,i));
for(j=0;j<N;j++)
printf("the average score of course%d is: %3.2f\n",j+1,course_average(stu,j));
highest(stu);
printf("Fangcha: %3.2f\n",fangcha(stu));
getch();
}
[此贴子已经被作者于2006-12-7 23:48:47编辑过]