Computer Science, asked by akanshaanand, 1 year ago

Write a program to find and display sum of rows and sum of columns of 2D array with proper header files?

Answers

Answered by KUMARCHHOTU
1
So here's another interesting task. I know, i'm on the right path, just something doesn't work here. Basicly I have to sum rows and columns of 2d array and then store the results in separate arrays, as far as the code is now, c
Answered by shishir38
2
Sum of row 1 = 6 Sum of row 2 = 15 ... ... Sum of column 3 = 18 /** * C program to find sum of elements of rows and columns of matrix */ #include <stdio.h> #define SIZE 3 // Matrix size int main() { int A[SIZE][SIZE]; int row, col, sum = 0; /* Input elements in matrix from user */ printf("Enter elements in matrix of size %dx%d: \n", SIZE, SIZE); for(row=0; row<SIZE; row++) { for(col=0; col<SIZE; col++) { scanf("%d", &A[row][col]); } } /* Calculate sum of elements of each row of matrix */ for(row=0; row<SIZE; row++) { sum = 0; for(col=0; col<SIZE; col++) { sum += A[row][col]; } printf("Sum of elements of Row %d = %d\n", row+1, sum); } /* Find sum of elements of each columns of matrix */ for(row=0; row<SIZE; row++) { sum = 0; for(col=0; col<SIZE; col++) { sum += A[col][row]; } printf("Sum of elements of Column %d = %d\n", row+1, sum); } return 0; }
Similar questions