#include "iostream.h"
int main()
{
const int STU_NUM=5;
const int COU_NUM=4;
int i,j;
float score[STU_NUM+1] [COU_NUM+1]={{78,85,83,65},{88,91,89,93},{72,65,54,75},{86,88,75,60},{69,60,50,72}};
for (i=0;i<STU_NUM;i++)
{
for(j=0;j<COU_NUM;j++)
{ score[i][COU_NUM]+=score[i][j];
score[STU_NUM][j]+=score[i][j];
}
score[i][COU_NUM]/=COU_NUM;
}
for(j=0;j<COU_NUM;j++)
score[STU_NUM][j]/=STU_NUM;
cout<<"学生编号\t课程1\t课程2\t课程3\t课程4\t个人平均\n";
for(i=0;i<STU_NUM;i++)
{
cout<<"学生"<<i+1<<"\t\t";
for(j=0;j<COU_NUM+1;j++)
cout<<score[i][j]<<'\t';
cout<<endl;
}
for(j=0;j<8*(COU_NUM+2);j++)
cout<<"-";
cout<<"\n课程平均成绩";
for(j=0;j<COU_NUM;j++)
cout<<"\t"<<score[STU_NUM][j];
cout<<endl;
return 0;
}
就是这句: float score[STU_NUM+1] [COU_NUM+1]={{78,85,83,65},{88,91,89,93},{72,65,54,75},{86,88,75,60},{69,60,50,72}};
可以用键盘输入这些数字吗?
完全可以
#include "iostream.h"
int main()
{
const int STU_NUM=5;
const int COU_NUM=4;
int i,j;
float score[STU_NUM+1] [COU_NUM+1];
cout<<"请输入数据:";
for( i = 0; i < STU_NUM; i++ )
{
for( j = 0; j < COU_NUM; j++ )
{
cout<<i+1<<"行"<<j+1<<"列:";
cin>>score[i][j];
cout<<endl;
}
}
for (i=0;i<STU_NUM;i++)
{
for(j=0;j<COU_NUM;j++)
{ score[i][COU_NUM]+=score[i][j];
score[STU_NUM][j]+=score[i][j];
}
score[i][COU_NUM]/=COU_NUM;
}
for(j=0;j<COU_NUM;j++)
score[STU_NUM][j]/=STU_NUM;
cout<<"学生编号\t课程1\t课程2\t课程3\t课程4\t个人平均\n";
for(i=0;i<STU_NUM;i++)
{
cout<<"学生"<<i+1<<"\t\t";
for(j=0;j<COU_NUM+1;j++)
cout<<score[i][j]<<'\t';
cout<<endl;
}
for(j=0;j<8*(COU_NUM+2);j++)
cout<<"-";
cout<<"\n课程平均成绩";
for(j=0;j<COU_NUM;j++)
cout<<"\t"<<score[STU_NUM][j];
cout<<endl;
return 0;
}
可以
#include "iostream.h"
int main()
{
const int STU_NUM=5;
const int COU_NUM=4;
int i,j;
float score[STU_NUM][COU_NUM];
for(i=0;i<STU_NUM;i++)
{
for(j=0;j<COU_NUM;j++)
cin >>score[i][j];
}
for (i=0;i<STU_NUM;i++)
{
for(j=0;j<COU_NUM;j++)
{ score[i][COU_NUM]+=score[i][j];
score[STU_NUM][j]+=score[i][j];
}
score[i][COU_NUM]/=COU_NUM;
}
for(j=0;j<COU_NUM;j++)
score[STU_NUM][j]/=STU_NUM;
cout<<"学生编号\t课程1\t课程2\t课程3\t课程4\t个人平均\n";
for(i=0;i<STU_NUM;i++)
{
cout<<"学生"<<i+1<<"\t\t";
for(j=0;j<COU_NUM+1;j++)
cout<<score[i][j]<<'\t';
cout<<endl;
}
for(j=0;j<8*(COU_NUM+2);j++)
cout<<"-";
cout<<"\n课程平均成绩";
for(j=0;j<COU_NUM;j++)
cout<<"\t"<<score[STU_NUM][j];
cout<<endl;
return 0;
}
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息