Non-Recursive Program:
Aim:
To know the sum of elements of a row.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,allrow=0,m,n,Row;
printf("Enter the rows and column size of a matrix");
scanf("%d%d",&m,&n);
printf("\nEnter the elements:");
for(i=0;i<m;i++)
{
for( j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nThe matrix is:");
for(i=0;i<m;i++)
{
for( j=0;j<n;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{ Row=0;
for(j=0;j<n;j++)
{
Row+=a[j][i];
}
allrow+=Row;
printf("\nThe %d Row sum is %d",i+1,Row);
}
printf("\nThe all Rows sum is %d",allrow);
}
No comments:
Post a Comment