Write C program to check even or odd using functions


Introduction

I have used Code::blocks 12 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

Write C program to check even or odd using functions


  1. #include <stdio.h>
  2.  
  3. int isEven(int num)
  4. {
  5. return !(num & 1);
  6. }
  7. int main()
  8. {
  9. int num;
  10.  
  11. // Inputting number from user
  12. printf("Enter any number: ");
  13. scanf("%d", &num);
  14.  
  15. // If isEven() function return 0 then the number is even
  16. if(isEven(num))
  17. {
  18. //printing even number
  19. printf("The number is even.");
  20. }
  21. else
  22. {
  23. //printing odd number
  24. printf("The number is odd.");
  25. }
  26.  
  27. return 0;
  28. }
  29.  

Result

C language

     





Related Topics




Popular Posts