WAP for sum of elements in matrix
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5][5],n,m,i,j,small;
int sum=0;
cout<<"\n enter size of rows :";
cin>>n;
cout<<"\n enter size of collumns :";
cin>>m;
cout<<"\n enter element of 2d array :";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
cout<<"\n 2d array \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n";
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
sum=sum+a[i][j];
}
cout<<"\n";
}
cout<<"\n The sum of every element :"<<sum;
getch();
clrscr();
}
No comments:
Post a Comment