分类: C/C++
2008-04-20 01:02:15
求学生学科平均成绩的方法Ⅱ(二维数组的初始化)
Author:yuexingtian
Date:Sunday, April 20, 2008
students |
Math |
C language |
Dbase |
Tommy long |
80 |
75 |
92 |
Jack chen |
61 |
65 |
71 |
Honey liu |
59 |
63 |
70 |
85 |
87 |
90 | |
Wu di |
76 |
77 |
85 |
/*求学生学科平均成绩的方法*/ void main() { int i,j,s=0,l,v[3]; static int a[5][3]={{80,75,92},{61,65,71},{59,63,70},{85,87,90},{76,77,85}}; for(i=0;i<3;i++)/*外循环(以列为循环对象)*/ { for(j=0;j<5;j++)/*内 s=s+a[j][i]; 循环*/ v[i]=s/5; s=0; } l=(v[0]+v[1]+v[2])/3; printf("math=%d\nc language=%d\ndbase=%d\n",v[0],v[1],v[2]); printf("total=%d\n",l); getch(); } |