现在的位置: 首页 > 综合 > 正文

用数组对学生成绩统计

2013年02月24日 ⁄ 综合 ⁄ 共 575字 ⁄ 字号 评论关闭

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
 int i,j,s1[3]={0,0,0},s2[4]={0,0,0,0};
 double ave1[3],ave2[4];
 int a[4][3]={{89,78,56},{88,99,100},{72,80,61},{60,70,75}};
 for(i=0;i<3;i++)
  {for(j=0;j<4;j++)
   s1[i]=s1[i]+a[j][i];
  ave1[i]=double(s1[i])/4;}
 cout<<"每门课程的学生平均成绩:"<<endl;
 for(i=0;i<3;i++)
  cout<<"课程"<<i+1<<"的学生平均成绩为:"<<ave1[i]<<endl;
 for(j=0;j<4;j++)
  {for(i=0;i<3;i++)
   s2[j]=s2[j]+a[j][i];
  ave2[j]=double(s2[j])/3;}
 cout<<"每个学生的各门课程平均成绩:"<<endl;
 for(j=0;j<4;j++)
  cout<<"学生"<<j+1<<"的各门课程平均成绩为:"<<fixed<<setprecision(2)<<ave2[j]<<endl;
 return 0;
}

抱歉!评论已关闭.