matrix with row-wise sum
#include<stdio.h>
#include<conio.h>
main()
{
int a[5][5],m,n,i,j,sum[5];
clrscr();
printf("\n enter the no. of rows of the matrix:");
scanf("%d",&m);
printf("\n enter the no. of columns of the matrix:");
scanf("%d",&n);
for(i=0;i<m;i++) /* scan the entire matrix */
for(j=0;j<n;j++)
{
printf("\n enter the a[%d][%d] element:",i+1,j+1);
scanf("%d",&a[i][j]);
}
if(m==n) /* check whether square matrix or not */
printf("\n The given matrix is a square matrix and ");
else
printf("\n The given matrix is not a square matrix and ");
printf("\n The elements of the given matrix are:");
for(i=0;i<m;i++) /* finding row-wise sum */
{
sum[i]=0;
for(j=0;j<n;j++)
sum[i]=sum[i]+a[i][j];
}
for(i=0;i<m;i++) /* print the matrix with row-sum */
{
printf("\n");
for(j=0;j<n;j++)
printf("\t %d ",a[i][j]);
printf("\t Row Sum=%d",sum[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int a[5][5],m,n,i,j,sum[5];
clrscr();
printf("\n enter the no. of rows of the matrix:");
scanf("%d",&m);
printf("\n enter the no. of columns of the matrix:");
scanf("%d",&n);
for(i=0;i<m;i++) /* scan the entire matrix */
for(j=0;j<n;j++)
{
printf("\n enter the a[%d][%d] element:",i+1,j+1);
scanf("%d",&a[i][j]);
}
if(m==n) /* check whether square matrix or not */
printf("\n The given matrix is a square matrix and ");
else
printf("\n The given matrix is not a square matrix and ");
printf("\n The elements of the given matrix are:");
for(i=0;i<m;i++) /* finding row-wise sum */
{
sum[i]=0;
for(j=0;j<n;j++)
sum[i]=sum[i]+a[i][j];
}
for(i=0;i<m;i++) /* print the matrix with row-sum */
{
printf("\n");
for(j=0;j<n;j++)
printf("\t %d ",a[i][j]);
printf("\t Row Sum=%d",sum[i]);
}
getch();
}
No comments:
Post a Comment