Thursday, July 25, 2013

Program to find the sum of all the elements of a matrix


#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int a[20][20],sum=0,m,n,i,j;
 cout<<"Enter the size of matrix : "
 cin>>m>>n;
 cout<<"Enter the elements : ";
 for(i=0;i<m;i++)
 for(j=0;j<n;j++)
 {
     cin>>a[i][j];
     sum+=a[i][j];
 }
 cout<<"Sum of elements of the matrix is : "<<sum
 getch();
}

No comments:

Post a Comment