Qn-9.c (826B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 06 Mar 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a C program to find sum of all elements in a given 2D array. */ 9 10 #include <stdio.h> 11 12 int findSum(int row, int col, int[row][col]); 13 14 int main() 15 { 16 int row = 3, col = 3, i, j, val = 1; 17 int arr[row][col]; 18 for (i = 0; i < row; i++) 19 { 20 for (j = 0; j < col; j++) 21 { 22 arr[i][j] = val++; 23 } 24 } 25 printf("Sum: %d", findSum(row, col, arr)); 26 return 0; 27 } 28 29 int findSum(int row, int col, int arr[row][col]) 30 { 31 int i, j; 32 int sum = 0; 33 for (i = 0; i < row; i++) 34 { 35 for (j = 0; j < col; j++) 36 { 37 sum += arr[i][j]; 38 } 39 } 40 return sum; 41 }