20_10

Write a C code to count the number of negative elements in a 2D matrix.

Source code:

 //Write a C code to count the number of negative elements in a 2D matrix.

#include<stdio.h>

int main()

{

int row, col, i, j, count=0;

int a[10][10];

printf("Enter the number of row & column:");

scanf("%d %d", &row, &col); 

printf("Enter the matrix:\n");

for (i=0; i<row; ++i)

{

for (j=0;j<col; ++j)

scanf("%d",&a[i][j]);

}

for (i=0; i<row; ++i)

{

for (j=0;j<col; ++j)

{

if(a[i][j]<0)

count = count + 1;

}

}

printf("No. of Negative Elements = %d",count);

return 0;

}

Output:

C code to count the number of negative elements in a 2D matrix


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...