Thursday, July 28, 2011

Sum of elements of a matrix

#include<stdio.h>
void main()

{
int i,n,m,j,sum=0,mat[10][10];
clrscr();
printf("Enter the no.of rows and colns of the matrix ");
scanf("%d%d",&m,&n);
printf("\nEnter the elements  : \n");
for(i=0;i<m;i++)
   for(j=0;j<n;j++)
    {
  scanf("%d",&mat[ i ][ j ]);
  sum+=mat[ i ][ j ];
    }
printf("\nEntered matrix is  : \n");

for(i=0;i<m;i++)
   {
   for(j=0;j<n;j++)
    {
  printf("%d\t",mat[ i ][ j ]);
    }
    printf("\n");
   }
printf("\nSum of the elements of the matrix  :%d",sum);
getch();
}

0 comments:

Post a Comment