Count Zeros in a 5x5 Matrix in C
Problem: Count how many zeros are in a given 5x5 matrix.
🔍 Explanation:
- Traverse all elements of the matrix.
- Increase a counter when an element is zero.
- Print the total count of zeros.
✅ C Program:
#include <stdio.h>
int main() {
int matrix[5][5];
int zeroCount = 0;
printf("Enter 25 elements of 5x5 matrix:\n");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
scanf("%d", &matrix[i][j]);
if (matrix[i][j] == 0) {
zeroCount++;
}
}
}
printf("Number of zeros in the matrix = %d\n", zeroCount);
return 0;
}
📤 Sample Output:
Number of zeros in the matrix = 6
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন