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


I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. static int Arr[10][10];
  7. int i, j, x, y;
  8. int even, odd;
  9.  
  10. cout<<"Enter the order of the matrix \n";
  11. //Inputing elements in matrix from user
  12. cin>>x;
  13. cin>>y;
  14. cout<<"Enter the coefficients of matrix\n";
  15.  
  16. /* Assuming that there are 0 even and odd elements */
  17. even = 0;
  18. odd = 0;
  19. for (i = 0; i < x; ++i)
  20. {
  21. for (j = 0; j < y; ++j)
  22. {
  23. cin>>Arr[i][j];
  24. if ((Arr[i][j] % 2) == 0)
  25. {
  26. ++even;
  27. }
  28. else
  29. ++odd;
  30. }
  31. }
  32. // Printing user's given matrix
  33. cout<<"The given matrix is \n";
  34. for (i = 0; i < x; ++i)
  35. {
  36. for (j = 0; j < y; ++j)
  37. {
  38. cout<<" "<<Arr[i][j];
  39. }
  40. cout<<"\n";
  41. }
  42. // Printing occurance of even and odd numbers
  43. cout<<"\n The frequency of occurance of odd number = "<<odd <<"\n";
  44. cout<<"\n The frequency of occurance of even number = "<<even <<"\n";
  45. }
  46.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts