Write C++ program to check even or odd using functions


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 isEven(int num)
  5. {
  6. return !(num & 1);
  7. }
  8.  
  9. int main(){
  10.  
  11. int num;
  12.  
  13. // Inputting number from user
  14. cout<<"Enter any number: ";
  15. cin>>num;
  16.  
  17. // If isEven() function return 0 then the number is even
  18. if(isEven(num))
  19. {
  20. //printing even number
  21. cout<<"The entered number is even.";
  22. }
  23. else
  24. {
  25. //printing odd number
  26. cout<<"The entered number is odd.";
  27. }
  28.  
  29. return 0;
  30.  
  31. }
  32.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts