C Program To Calculate Sum of Array Elements
Learn How To Calculate Sum of Array Elements in C Programming. Here, the Array is a 2-Dimensional Array or a Matrix. It is important that we should know How For Loop Works before getting further with the C Program Code.
Since this is a 2 Dimensional Array, we are taking 2 For Loops to add elements of Rows and Columns.
Also Read: C Program To Find Transpose of Matrix
Note: This C Program To Find Addition of Array Elements is developed using gEdit Editor and compiled using GCC in Linux Ubuntu Operating System.
C Program To Find Sum of Array Elements
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include<stdio.h> int main() { int arr[10][10]; int row, col, sum = 0, i = 0, j = 0; printf("\nEnter Number of Rows: "); scanf("%d", &row); printf("\nEnter Number of Columns: "); scanf("%d", &col); printf("Enter Matrix Elements\n"); for(i = 0; i < row; i++) { for(j = 0; j < col; j++) { scanf("%d", &arr[i][j]); } } printf("\nMatrix Elements\n"); for(i = 0; i < row; i++) { for(j = 0; j < col; j++) { printf("%d\t", arr[i][j]); } printf("\n"); } for(i = 0; i < row; i++) { for(j = 0; j < col; j++) { sum = sum + arr[i][j]; } } printf("\nSum of Array Elements: %d", sum); printf("\n"); return 0; } |
Output

If you have any compilation errors or doubts in this C Program To Add Array Elements, let us know about it in the Comment Section below.