Saturday, 25 October 2014

Sum of Elements of Matrix ( C Program )

Non-Recursive C Program:

Aim:To add all the elements of given matrix.

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
  int a[10][10],i,j,m,n,sum=0;
clrscr();
printf("Enter the order of matrix:\n");
scanf("%d%d",&m,&n);

Printf("\nEnter the elements of matrix:");
  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]);
       }
    }

  for ( i=0;i<m;i++)
   {
     for( j=0;j<n;j++)
      {
         sum+ = a[i][j]
       }
    }
Printf("\nThe sum of elements of matrix:%d",sum);
}

Click here to view matrix related programs.

No comments:

Post a Comment