该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
当个反面典型,让大家见识下丑陋无比的程序好了,主要是想练练打字,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&#61;1;k<&#61;3;k&#43;&#43;)
{
stu1.score[k]&#61;rand()%100;
stu2.score[k]&#61;rand()%100;
stu3.score[k]&#61;rand()%100;
stu4.score[k]&#61;rand()%100;
}
result1&#61;average(stu1.score);
result2&#61;average(stu2.score);
result3&#61;average(stu3.score);
result4&#61;average(stu4.score);
for (i&#61;1;i<&#61;3;i&#43;&#43;)
{
printf("The 1st student&#39;s score %d is %d\n",i,stu1.score[i-1]);
printf("The 2nd student&#39;s score %d is %d\n",i,stu2.score[i-1]);
printf("The 3nd student&#39;s score %d is %d\n",i,stu3.score[i-1]);
printf("The 4th student&#39;s score %d is %d\n",i,stu4.score[i-1]);
}
printf("The 1st student&#39;s score is %d\n",result1);
printf("The 2nd student&#39;s score is %d\n",result2);
printf("The 3rd student&#39;s score is %d\n",result3);
printf("The 4th student&#39;s score is %d\n",result4);
}