Advertisement
Networking101

OddorEven

Dec 10th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <filesystem>
  4.  
  5. using std::cout;
  6. using std::endl;
  7. using std::cin;
  8.  
  9. bool checkEvenOdd(int num);
  10.  
  11.     int main() {
  12.         int num;
  13.         bool isEven;
  14.         cout << "Enter any number: ";
  15.         //Storing the entered value in variable num
  16.         cin >> num;
  17.         //Calling the function that checks even odd
  18.         isEven = checkEvenOdd(num);
  19.         if (isEven)
  20.             cout << num << " is an even number";
  21.         else
  22.             cout << num << " is an odd number";
  23.  
  24.         return 0;
  25.     }
  26.     /* This function checks whether the passed number is even
  27.      * or odd. If the number is even then this function returns
  28.      * true else it returns false.
  29.      */
  30.     bool checkEvenOdd(int num) {
  31.         bool b;
  32.         /* If number is perfectly divisible by 2 then it is
  33.          * an even number else it is an odd number
  34.          *
  35.          */
  36.         if (num % 2 == 0)
  37.             b = true;
  38.         else
  39.             b = false;
  40.  
  41.         return b;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement