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


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

Result

C language techstudy.org

     






Related Topics




Popular Posts