write a C program to count the number of zero elements in a two dimensional matrix using function with 2D array as an argument
Sample input:
12 0 38
4 3 0
7 0 9
No of zero elements:3
#include <stdio.h>
int main(void) {
int array[3][3]; // array of 3 rows and 3 columns
int count = 0; // number of zero elements in the array
printf("Enter the elements of two dimensional array : ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
scanf("%d",&array[i][j]);
}
}
// count the number of zero elements
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(array[i][j] == 0)
count++;
}
}
printf("\nNo of zero elements : %d", count);
return 0;
}
Output:
Enter the elements of two dimensional array :
12 0 38
4 3 0
7 0 9
No of zero elements : 3
Comments
Leave a comment