bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / eduincs_exam / Paper-1_05-03-2026 / Qn-9.c

Qn-9.c (635B)


      1 /* Write a C program to find sum of all elements in a given 2D array. */
      2 
      3 #include <stdio.h>
      4 
      5 int findSum(int row, int col, int[row][col]);
      6 
      7 int main()
      8 {
      9     int row = 3, col = 3, i, j, val = 1;
     10     int arr[row][col];
     11     for (i = 0; i < row; i++)
     12     {
     13         for (j = 0; j < col; j++)
     14         {
     15             arr[i][j] = val++;
     16         }
     17     }
     18     printf("Sum: %d", findSum(row, col, arr));
     19     return 0;
     20 }
     21 
     22 int findSum(int row, int col, int arr[row][col])
     23 {
     24     int i, j;
     25     int sum = 0;
     26     for (i = 0; i < row; i++)
     27     {
     28         for (j = 0; j < col; j++)
     29         {
     30             sum += arr[i][j];
     31         }
     32     }
     33     return sum;
     34 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror