Skip to main content

C Program to find the sum of the elements of a 2-D array.

 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

Popular posts from this blog

C Program to Print first N Even Natural Number/in Reverse Order

  C Program to Print first N Even Natural Number.     In this example, we will find and print the first N even natural. Here we have used for loop to solve this program.      What are Natural Numbers? Natural Numbers are all positive numbers starting from 1 to infinity.      For Example:  1,2,3,4,5,6,.............................,n are all natural numbers. What are Even Numbers? Even numbers are those numbers whose remainder is 0 when divided by 2.     For Example: 2,4,6,8,10,.....,n are all even numbers.   PROGRAM: #include <stdio.h> #include <conio.h> void   main () {      int   i , x ;      printf ( "Enter the value of N : " );      scanf ( " %d " ,& x );      for ( i = 1 ; i <= x ; i ++)     {          printf ( " %d " , 2 * i );     }      getch (); } OUTPUT: C Program to Print First N Even Natural Number in Reverse Order. PROGRAM 123 #include <conio.h> #include <stdio.h> int   main () {      int   i , x ;      printf