recent

C Program Addition Of All Elements In Matrix(2D-Array)

C Program Addition Of All Elements In Matrix(2D-Array)

#include<stdio.h>

int main()
{

 int i, j, mat[10][10], row, col;
   int sum = 0;

   printf("Enter the number of Rows :\n ");
   scanf("%d", &row);  //input from user

   printf("Enter the number of Columns :\n ");
   scanf("%d", &col);    //input from user

 
   for (i = 0; i < row; i++)
    {
      for (j = 0; j < col; j++)
 {
         printf("Enter the Element mat[%d][%d] : \n", i, j);
         scanf("%d", &mat[i][j]);   //array element entry
          }
   }


   for (i = 0; i < row; i++)
   {
      for (j = 0; j < col; j++)
  {
         sum = sum + mat[i][j];
       }
   }

   printf("Sum of All Elements in Matrix : %d\n", sum);   //Print out the Result
}
Powered by Blogger.