#include<stdio.h>
#include<stdlib.h>
int main()
{
int **a;
int i,j,m,n,sum=0;
printf("Enter number of rows:");
scanf("%d",&m);
printf("Enter number of columns:");
scanf("%d",&n);
a=(int**) malloc(m * sizeof(int*));
for(i=0;i<m;i++)
{
a[i]=(int*) malloc(n * sizeof(int));
}
printf("Enter %d by %d matrix:\n",m,n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nYou Enterd Matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
sum=sum+a[i][j];
}
}
printf("The sum of all elements of Matrix is:-%d",sum);
return 0;
}
**** INPUT && OUTPUT ****
0 Comments