Computer Science, asked by astudas2839, 9 months ago

Write a program to input n x m matrix and find the sum of all numbers.

Answers

Answered by mohishkhan9996
3

Answer:

hey... mate

Input : mat[] = {{1, 1, 2},

{2, 3, 3},

{4, 5, 3}}

Output : 18

The even occurring elements are 1, 2 and their number

of occurrences are 2, 2 respectively. Therefore,

sum = 1+1+2+2 = 6.

Input : mat[] = {{10, 20},

{40, 40}}

Output : 80

plzz mark as brainlist...xd

Answered by ridhimakh1219
1

Write a program to input n x m matrix and find the sum of all numbers.

Explanation:

C Program to read  n x m matrix and find sum of all elements of two dimensional array

#include <stdio.h>

#define MAXROW  10

#define MAXCOL  10

int main()

{

int matrix[MAXROW][MAXCOL];

int i,j,n,m;

int sum;

printf("Enter number of rows :");

scanf("%d",&n);

printf("Enter number of Columns :");

scanf("%d",&m);

printf("\nEnter 2d array elements :\n");

for(i=0;i< n;i++)

{

 for(j=0;j<m;j++)

 {

  printf("Enter element [%d,%d] : ",i+1,j+1);

  scanf("%d",&matrix[i][j]);

 }

}

/*sum of all elements*/

sum=0;

for(i=0;i<n;i++)

{

 for(j=0;j<m;j++)

 {

  sum+=matrix[i][j];

 }

}

printf("\nSum of all elements : %d",sum);

return 0;

}

Output

Enter number of rows :3                          

Enter number of Columns :3

Enter 2d array elements :  

Enter element [1,1] : 22                     

Enter element [1,2] : 11                      

Enter element [1,3] : 9                      

Enter element [2,1] : 6                      

Enter element [2,2] : 34                              

Enter element [2,3] : 43                        

Enter element [3,1] : 89                        

Enter element [3,2] : 45                        

Enter element [3,3] : 32                                                                    

Sum of all elements : 291

Similar questions