0% found this document useful (0 votes)
30 views1 page

Write A Program To Calculate Sum of

Uploaded by

Sid1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

Write A Program To Calculate Sum of

Uploaded by

Sid1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//Write a program to calculate sum of all elements of a matrix.

#include<stdio.h>
#include<conio.h>
#define rows 10
#define cols 10

void main()
{
int r,c,i,j,a[rows][cols],sum=0;
clrscr();

Lb:printf("\nHow many rows and columns: ");


scanf("%d%d",&r,&c);

if((r<=0||r>rows)&&(c<=0||c>cols))
{
printf("\nInvalid size.");
goto Lb;
}

printf("\nEnter elements: \n");


for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}

for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
sum+=a[i][j];
}
}

printf("\nSum of the elements of the matrix is %d.",sum);


getch();
}

You might also like