//PROGRAM FOR SUM OF ROW AND COLUMN OF NON SQUARE/SQUARE MATRIX
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k,A[10][10],R_S,C_S,r,c;
clrscr();
printf(" ENTER THE SIZE OF A MATRIX \n");
scanf("%d%d",&r,&c);
printf("ENTER THE ELEMENT OF A MATRIX \n");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&A[i][j]);
/* Sum of rows */
for(i=0;i<r;i++)
{
R_S=0;
for(j=0;j<c;j++)
{
R_S=R_S+A[i][j];
}
printf("\nSum of %d row is %d",i+1,R_S);
}
/* Sum of Column */
for(i=0;i<c;i++)
{
C_S=0;
for(j=0;j<r;j++)
{
C_S=C_S+A[j][i];
}
printf("\nSum of %d Col is %d",i+1,C_S);
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k,A[10][10],R_S,C_S,r,c;
clrscr();
printf(" ENTER THE SIZE OF A MATRIX \n");
scanf("%d%d",&r,&c);
printf("ENTER THE ELEMENT OF A MATRIX \n");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&A[i][j]);
/* Sum of rows */
for(i=0;i<r;i++)
{
R_S=0;
for(j=0;j<c;j++)
{
R_S=R_S+A[i][j];
}
printf("\nSum of %d row is %d",i+1,R_S);
}
/* Sum of Column */
for(i=0;i<c;i++)
{
C_S=0;
for(j=0;j<r;j++)
{
C_S=C_S+A[j][i];
}
printf("\nSum of %d Col is %d",i+1,C_S);
}
getch();
}
No comments:
Post a Comment