Doing simple calculation in if statement - C++ Statement

C++ examples for Statement:if

Description

Doing simple calculation in if statement

Demo Code

#include <iostream>
using namespace std;
int main()/*  w  w w.  j av  a 2  s  . co  m*/
{
   int  n;
   // Get a number n from the keyboard.
   cout << "Enter a number and press ENTER: ";
   cin >> n;
   // Get remainder after dividing by 2.
   // If remainder is 0, then n is even.
   if (n % 2 == 0) {
      cout << "The number is even.";
   } else {
      cout << "The number is odd.";
   }
   return 0;
}

Result


Related Tutorials