C++ Online Compiler
Example: Divisibility and Parity Checker in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Divisibility and Parity Checker #include <iostream> using namespace std; int main() { int number; // Step 1: Prompt the user to enter a number cout << "Enter an integer: "; cin >> number; // Step 2: Determine if the number is Even or Odd if (number % 2 == 0) { cout << "The number " << number << " is Even." << endl; } else { cout << "The number " << number << " is Odd." << endl; } // Step 3: Determine if the number is divisible by 2 // (This is inherently checked by the Even/Odd logic, but explicitly stated for clarity) if (number % 2 == 0) { cout << "The number " << number << " is divisible by 2." << endl; } else { cout << "The number " << number << " is not divisible by 2." << endl; } // Step 4: Determine if the number is divisible by 3 if (number % 3 == 0) { cout << "The number " << number << " is divisible by 3." << endl; } else { cout << "The number " << number << " is not divisible by 3." << endl; } return 0; }
Output
Clear
ADVERTISEMENTS