Answer to Question #149457 in C++ for Jochelle Buenaventura

Question #149457
Create a program using two-dimensional arrays that computes the sum of data in rows and the sum of data in columns of the 3x3 (three by three) array variable n[3[3].
Sample input/output dialogue:
5 9 8 = 22
3 8 2 = 13
4 3 9 = 16
---------------------
12 20 19
1
Expert's answer
2020-12-08T05:42:45-0500
#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; 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog