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
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ