C program to find the frequency of odd numbers and even numbers in the input of a matrix

by Nideesh C on April 13, 2011 · 1 comment

in C Programming




/*  C program to find the frequency of odd numbers and even numbers in the input of a matrix  */

#include <stdio.h>

void main ()
{
static int ma[10][10];
int i,j,m,n,even=0,odd=0;

printf (“Enter the order ofthe matrix \n”);
scanf (“%d %d”,&m,&n);

printf (“Enter the coefficients if matrix \n”);
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
scanf (“%d”, &ma[i][j]);
if ((ma[i][j]%2) == 0)
{
++even;
}
else
++odd;
}
}
printf (“The given matrix is\n”);
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (” %d”,ma[i][j]);
}
printf (“\n”);
}

printf (“\nThe frequency of occurrence of odd number  = %d\n”,odd);
printf (“The frequency of occurrence of even number = %d\n”,even);

}      /* End of main() */

/*—————————————————–
Output
Enter the order of the matrix
3 3
Enter the coefficients if 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 occurrence of odd number  = 5
The frequency of occurrence of even number = 4

——————————————————-*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to read A (MxN), find the transpose of a given matrix and output both the input matrix and the transposed matrix.
  2. C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
  3. C program to read two matrices A (MxN) and B(MxN) and perform addition OR subtraction of A and B. Find the trace of the resultant matrix. Output the given matrix, their sum or Differences and the trace.
  4. C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
  5. C Program to check if a given matrix is an identity matrix

Leave a Comment

{ 1 trackback }

Previous post:

Next post: