#include <iostream>//for cin, cout
using namespace std;
//The start point of the program
int main() {
//two-dimensional array tos store values
int n[3][3];
int sums[3][2];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
//get value from the user
cout << "Enter value ["<<(i)<<"]["<<(j)<<"]: ";
cin>>n[i][j];
sums[i][0]=0;
sums[i][1]=0;
}
}
//computes the sum of data in rows and the sum of data in columns
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
sums[i][0]+=n[i][j];
sums[i][1]+=n[j][i];
}
}
//display result
cout<<endl;
for(int i=0;i<3;i++){
//display values
for(int j=0;j<3;j++){
cout<<n[i][j]<<" ";
}
//display the sum of data in rows
cout<<" = "<<sums[i][0]<<endl;
}
//display the sum of data in columns
cout<<"--------------"<<endl;
for(int i=0;i<3;i++){
cout<<sums[i][1]<<" ";
}
cout<<endl;
//Delay
system("pause");
return 0;
}
Comments
Leave a comment