c++例题编程

来源:百度知道 编辑:UC知道 时间:2024/06/08 14:05:16
定义一个3行4列的的数组(用来存储3个学生的成绩,每个学生4门成绩;),然后循环输入对其赋值,然后分别计算输出第0个学生的总分,和3个人第0科成绩
小弟初学,现求教各位前辈,本人感激不尽。

#include<iostream>
using namespace std;
int main()
{
int i,j,a[3][5];
cout<<"please input the array:"<<endl;
for (i=0;i<3;i++)
for (j=0;j<4;j++)
cin>>a[i][j];
a[0][4]=a[0][0]+a[0][1]+a[0][2]+a[0][3];
cout<<a[0][4]<<endl;
cout<<a[2][0]<<endl;
return 0;
}

#include<iostream>
using namespace std;
int main(){
int x,y,A[3][5];
for (x=0;x<3;x++) for (y=0;y<4;y++) cin>>A[x][y];
for (x=0;x<3;x++)A[x][4]=A[x][0]+A[x][1]+A[x][2]+A[x][3];
cin>>o;
cout<<A[o][4]<<endl;
cout<<A[0][o]<<' '<<A[1][o]<<' '<<A[2][o];
system("pause");
return 0;
}