Saturday, March 3, 2012

PROGRAM TO FIND SUM OF ALL ELEMENTS OF MATRIX USING FUNCTION


/********************(soeasyprograms.blogspot.in)**************************/
#include<stdio.h>
#include<conio.h>
/* A program to calculate the sum of all the elements of matrix"*/
int sum(int a[10][10],int m,int n)
{
   int i,j,sum=0;
   for(i=1;i<=m;i++)
   {
   for(j=1;j<=n;j++)
    {
    sum+=a[i][j];
    }
   }
   return sum;

}




void main()
{
   int a[10][10],i,j,m,n,total;
   clrscr();
   printf("enter the order of A matrix");
   printf("\nenter the number of rows: ");
   scanf("%d",&m);
   printf("\nenter the number of columns: ");
   scanf("%d",&n);
   printf("\nenter the elements of A: ");
   for(i=1;i<=m;i++)
   {
   for(j=1;j<=n;j++)
    {
      scanf("%d",&a[i][j]);
    }
   }
   printf("\n A matrix is:");
   for(i=1;i<=m;i++)
   {
   printf("\n");
   for(j=1;j<=n;j++)
    {
      printf(" %d",a[i][j]);
    }
   }
   total=sum(a,m,n);

printf("\nsum of all the elements of matrix is=%d",total);
   getch();
return 0;
   }


/********************(soeasyprograms.blogspot.in)*************************/

No comments:

Post a Comment