Write a program to take 3 by 3 matrix from user and display their sum

 Here We are taking input from user for 3 by 3 matrix and we are using 4 integers as variable a, i, j and sum. 

/*Write a program to take 3 by 3 matrix from user and display their sum*/

#include<iostream>

using namespace std;

int main(){

int a[3][3],i,j,sum=0;

cout<<"Enter 3 by 3 matrix:"<<endl;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

cin>>a[i][j];


for(i=0;i<3;i++)

for(j=0;j<3;j++)

sum+=a[i][j];

cout<<"The sum is:"<<sum;

return 0;}


0 Comments had been done yet:

Post a Comment