Program to accept values in 2-Dimensional 3 by 3 arrays and displays the sum of all the elements.
Code:
#include <stdio.h>
#include<conio.h>
int main()
{
int i,j,n,m,sum=0,a[20][20];
printf("Enter number of rows and columns:");
scanf("%d%d",&n,&m);
for(i=0;i<=n-1;i++)
{
for(j=0;j<=m-1;j++)
{
printf("Enter a Value:");
scanf("%d",&a[i][j]);
}
}
for(i=0;i<=n-1;i++)
{
for(j=0;j<=m-1;j++)
{
sum=sum+a[i][j];
}
}
printf("Sum of Elements=%d",sum);
getch();
return 0;
}
Sample Input and Output:
Enter number of rows and columns:3
3
Enter a Value:2
Enter a Value:6
Enter a Value:4
Enter a Value:2
Enter a Value:4
Enter a Value:2
Enter a Value:1
Enter a Value:2
Enter a Value:3
Sum of Elements=26
In this article we are going see how to write
Program to accept values in 2-Dimensional 3 by 3 arrays and displays the sum of all the elements.So Let's start!
Explanation of Above Program
In the first line of code we are importing stdio.h header file which enable us to use some of the built-in function defined in
If you any have doubt,suggestion regarding this post or website then feel free to share with us.
If you have learned something new from this post then share this post with your family and
friends.
friends.