TOTAL OF ALL ELEMENTS.*/
#include
#include
main()
{
int a[10][10],i,j,m,n;
clrscr();
printf("\nENTER THE SIZE OF THE MATRIX");
scanf("%d%d",&m,&n);
printf("\n\nENTER THE ELEMENTS:");
for(i=0;i< m;i++)
{
for(j=0;j< n;j++)
scanf("%d",&a[i][j]);
}
printf("\n\nENTERED ELEMENTS IN A MATRIX ARE:");
printf("\n\n");
for(i=0;i< m;i++)
{
for(j=0;j< n;j++)
{
printf("%d",a[i][j]);
printf(" ");
}
printf("\n\n");
}
for(i=0;i< m;i++)
{
a[i][n]=0;
for(j=0;j< n;j++)
a[i][n]+=a[i][j];
}
for(j=0;j< n;j++)
{
a[m][j]=0;
for(i=0;i< m;i++)
a[m][j]+=a[i][j];
}
a[m][n]=0;
for(i=0;i< m;i++)
a[m][n]+=a[i][n];
printf("\n\n");
for(i=0;i< m+1;i++)
{
for(j=0;j< n+1;j++)
{
printf("%d",a[i][j]);
printf(" ");
}
printf("\n\n");
}
getch();
}
/*-----------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
ENTER THE SIZE OF THE MATRIX3
3
ENTER THE ELEMENTS:1 2 3
1 2 3
1 2 3
ENTERED ELEMENTS IN A MATRIX ARE:1 2 3
1 2 3
1 2 3
1 2 3 6
1 2 3 6
1 2 3 6
3 6 9 18
*/
No comments:
Post a Comment