PROGRAM TO ADD ALL THE ELEMENTS OF A MATRIX

/*PROGRAM TO ADD ALL THE ELEMENTS OF A MATRIX*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,m,n,a[8][8],sum=0;
clrscr();
printf(“Enter the order of the matrix: “);
scanf(“%d%d”,&m,&n);
printf(“\nEnter %d elements in the matrix:\n\n”,m*n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf(“%d”,&a[i][j]);
}
printf(“\nThe entered matrix of %d*%d order is:\n\n”,m,n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf(“%4d”,a[i][j]);
sum=sum+a[i][j];
}
printf(“\n”);
}
printf(“\nSum of elements of given matrix is: %d”,sum);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *