adspace


problem no.3
- write a program using two dimentional arrays that
compute
the sum of data in rows and sum of data in columns of
the 3*3 array variable.

sample input/output dialog

5 9 8 = 22
3 8 2 = 13
4 3 9 = 16
_____________
12 20 19

Answer Posted / janel

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int ar[3][3];
int a,b,R1,R2,R3,C1,C2,C3;

cout<<"Please Enter 9 numbers:"<<endl;
for (a=0;a<3;a++){
for (b=0;b<3;b++){

cout<<"["<<a<<"]["<<b<<"]:";
cin>>ar[a][b];
}
}
cout<<"The sum of the first row is: ";
R1=ar[0][0]+ar[0][1]+ar[0][2];
cout<<R1;
cout<<"\nThe sum of the second row is: ";
R2=ar[1][0]+ar[1][1]+ar[1][2];
cout<<R2;
cout<<"\nThe sum of the third row is: ";
R3=ar[2][0]+ar[2][1]+ar[2][2];
cout<<R3;

cout<<"\nThe sum of the first column is: ";
C1=ar[0][0]+ar[1][0]+ar[2][0];
cout<<C1;
cout<<"\nThe sum of the second column is: ";
C2=ar[0][1]+ar[1][1]+ar[2][1];
cout<<C2;
cout<<"\nThe sum of the third column is: ";
C3=ar[0][2]+ar[1][2]+ar[2][2];
cout<<C3<<endl;
getch();
system("pause");
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

No New Questions to Answer in this Category !!    You can

Post New Questions

Answer Questions in Different Category