🔍 Row-wise Sum of a 4x2 Matrix in C

⬅️ Previous

Row-wise Sum of a 4x2 Matrix in C

Problem: Write a program to compute and display the sum of each row in a 4x2 matrix.

🔍 Explanation:

  • The matrix has 4 rows and 2 columns.
  • Use nested loops to input elements and calculate the sum of each row.
  • Print the sum for each row separately.

✅ C Program:


#include <stdio.h>

int main() {
    int matrix[4][2];
    int rowSum;

    printf("Enter 8 elements for 4x2 matrix:\n");
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
            scanf("%d", &matrix[i][j]);
        }
    }

    for (int i = 0; i < 4; i++) {
        rowSum = 0;
        for (int j = 0; j < 2; j++) {
            rowSum += matrix[i][j];
        }
        printf("Sum of row %d = %d\n", i + 1, rowSum);
    }

    return 0;
}
  

📤 Sample Output:

Sum of row 1 = 3
Sum of row 2 = 7
Sum of row 3 = 11
Sum of row 4 = 15
  

row-wise sum in C, sum of each row in matrix C, 4x2 matrix sum in C, matrix row sum program, C programming 2D array, matrix operations in C, nested loops example in C #CProgramming #MatrixSum #RowSum #2DArray #LearnC #CProgram #CodingInC #CProgrammingTutorial #MatrixOperations

āĻ•োāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāχ:

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ