Answers for "how to check for even numbers in c++"

C++
0

c++ check if number is even or odd

#include <iostream>
using namespace std;
int main() {
   int num = 7;
   if((num & 1) == 0)
   cout<<num<<" is even";
   else
   cout<<num<<" is odd";
   return 0;
}
Posted by: Guest on August-03-2021
0

check even or odd c++

#include<iostream>
using namespace std;

int main()
{
  int num1 , num2;   // Declaration of two variables
  cout<<"Please enter the first number: ";
  cin>>num1;  // Taking the first number as input

  cout<<"Please enter the second number: ";
  cin>>num2;   // Taking the second number as input

  if(num1 % 2 == 0)  // if the remainder is zero so the number is divisible by 2 and it is an even number
    cout<<"The first number is Even\n";
  else    // if the remainder is not equal 2 so the number is not divisible by 2 and it is an odd number
    cout<<"The first number is Odd\n";

  if(num2 % 2 == 0)
    cout<<"The second number is Even\n";
  else
    cout<<"The second number is Odd\n";

  return 0;
}
Posted by: Guest on April-08-2022

Code answers related to "how to check for even numbers in c++"

Browse Popular Code Answers by Language