C Program to find the sum of the elements of a 2-D array.
In this example, we will find the sum of the elements of a 2-D array allowing the user to enter the row size and column size according to their requiremnts.
Here in the output we have entered a row size 3 and column size 3.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50],r,c,i,j,sum=0;
printf("Enter the row size and column size of the array :");
scanf("%d%d",&r,&c);
printf("Enter the elements of the array : ");
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=sum+a[i][j];
}
}
printf("The sum of the elements of the array is = %d",sum);
getch();
}
OUTPUT
Enter the row size and column size of the array :3
3
Enter the elements of the array : 12
4
65
1
32
73
58
36
45
The sum of the elements of the array is = 326
NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section. Let's Learn together.
MOTTO:
You Learn, I Learn together We Learn.
Comments
Post a Comment
Please do not spam any link