Answer to Question #225203 in C for Santhosh S

Question #225203

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


1
Expert's answer
2021-08-12T07:46:25-0400
#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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS