I have used CodeBlocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
#include <stdio.h>
void main()
{
static int Arr[10][10];
int i, j, x, y;
int even, odd;
printf("Enter the order of the matrix \n");
//Inputing elements in matrix from user
scanf("%d %d", &x, &y);
printf("Enter the coefficients of matrix \n");
/* Assuming that there are 0 even and odd elements */
even = 0;
odd = 0;
for (i = 0; i < x; ++i)
{
for (j = 0; j < y; ++j)
{
scanf("%d", &Arr[i][j]);
if ((Arr[i][j] % 2) == 0)
{
++even;
}
else
++odd;
}
}
// Printing user's given matrix
printf("The given matrix is \n");
for (i = 0; i < x; ++i)
{
for (j = 0; j < y; ++j)
{
printf(" %d", Arr[i][j]);
}
printf("\n");
}
// Printing occurance of even and odd numbers
printf("\n The frequency of occurance of odd number = %d \n", odd);
printf("The frequency of occurance of even number = %d\n", even);
}
I have used CodeBlocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Result:
Enter the order of the matrix
3
3
Enter the coefficients of matrix
1
2
3
4
5
6
7
8
9
The given matrix is
1 2 3
4 5 6
7 8 9
The frequency of occurance of odd number = 5
The frequency of occurance of even number = 4
need an explanation for this answer? contact us directly to get an explanation for this answer