C++ Program to Find the Frequency of Odd & Even Numbers in the given Matrix














































C++ Program to Find the Frequency of Odd & Even Numbers in the given Matrix



Program:
#include <stdio.h>
 
int  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 occurance of odd number  = %d\n",odd);
 
printf ("The frequency of occurance of even number = %d\n",even);
 
}
Ouput:
Enter the order ofthe 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 occurance of odd number  = 5
The frequency of occurance of even number = 4



More Articles of Shaik Aftab Ahmed:

Name Views Likes
C++ Program to Find the Frequency of Odd & Even Numbers in the given Matrix 434 1
C++ program to Sort a Linked List Using Merge Sort 389 1
C++ Program to Implement a Linked List representation of a Binary tree 412 1
C++ Program to Check for balanced parentheses in an expression 268 1
C++ Program to Perform Inorder, Preorder, Postorder traversals in a binary tree. 318 1
C++ program to print Indian flag 432 1
C++ program to Convert a multi level linked list to a singly linked list 312 1
C++ program to print right view of a Binary tree using queue 263 1
C++ Program to implement Huffman Coding Compression Algorithm 2037 1
C++ Program to Create a Height Balanced Binary Tree 300 1
C++ program to implement Prims algorithm 1005 1
C++ Program for BFS Traversal 324 1
C++ Progam to Evaluate a Prefix Expression 568 1
C++ Program to Implement Queue using Linked List 291 1
C++ implementation of Stack using Linked list 355 1
C++ program to find the intersection point of two linked lists 385 1
C++ program to count the inversions in the given array 292 1
C++ program to perform D.N.F sort 342 1
C++ program to print all possible subsets of a String 306 1
C++ program to count the number of ones in a binary representation of a number 333 1
C++ program to print all possible subsets of a set 336 1
C++ program to find the largest word in a String 302 1
C++ Program to print a matrix in Spiral order 408 1
C++ program to convert from Binary to Decimal, Octal to Decimal, Hexadecimal to Decimal 332 1
C limits library 369 1
Program to add two Binary numbers 360 1

Comments