该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
当个反面典型,让大家见识下丑陋无比的程序好了,主要是想练练打字,HOHO。应该用二维数组且全部函数化的,rand的%后面或是101或是100,可能和编译器有关,TC2下应写100,我那时候试好像是这样,吃饭鸟,类型就不管了。
struct student
{
int score[3];
}stu1,stu2,stu3,stu4;
int average(int *p)
{
return ((*p)+(*(p+1))+(*(p+2)))/3;
}
void main()
{
int i;
int j=20;
int k;
int result1,result2,result3,result4;
clrscr();
for (k=1;k<=3;k++)
{
stu1.score[k]=rand()%100;
stu2.score[k]=rand()%100;
stu3.score[k]=rand()%100;
stu4.score[k]=rand()%100;
}
result1=average(stu1.score);
result2=average(stu2.score);
result3=average(stu3.score);
result4=average(stu4.score);
for (i=1;i<=3;i++)
{
printf("The 1st student's score %d is %d\n",i,stu1.score[i-1]);
printf("The 2nd student's score %d is %d\n",i,stu2.score[i-1]);
printf("The 3nd student's score %d is %d\n",i,stu3.score[i-1]);
printf("The 4th student's score %d is %d\n",i,stu4.score[i-1]);
}
printf("The 1st student's score is %d\n",result1);
printf("The 2nd student's score is %d\n",result2);
printf("The 3rd student's score is %d\n",result3);
printf("The 4th student's score is %d\n",result4);
}