Program to display the sum of each row elements

Program to display the sum of each row elements
//Program to display the sum of each row elements
#include<iostream.h>
#include<conio.h>
#include <math.h>
void main()
{ clrscr();
 int P[10][10],m,n,i,j,sum1=0;
 cout<<"\n enter the no of rows for P:";
 cin>>m;
 cout<<"\n enter the no of columns for P:";
 cin>>n;
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
   cout<<"\n enter P["<<i<<"]["<<j<<"] elements:";
   cin>>P[i][j];
  }
 }
cout<<"\n the matrix P is:";
for (i=0;i<m; i++)
{cout<<"\n";
for(j=0; j<n; j++)
cout<<P[i][j]<<" ";
}
for(i=0;i<m; i++)
{sum1=0;
for(j=0; j<n; j++)
sum1+=P[i][j];
cout<<"\n Sum of row"<<i+1<<"="<<sum1;
}
getch();
}
Program to display the sum of each row elements Program to display the sum of each row elements Reviewed by SHERE KHOJRAHA on February 14, 2019 Rating: 5

No comments:

Powered by Blogger.