Saturday, 25 October 2014

Sum of Column Elements of Matrix

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,allcol=0,m,n,Col;
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++)
   {   Col=0;
     for(j=0;j<n;j++)
       {
          Col+=a[i][j];
        }
    allcol+=Col;
printf("\nThe %d Row sum is %d",i+1,Col);
    }
printf("\nThe all Rows sum is %d",allcol);
}

No comments:

Post a Comment