Search
 
SCRIPT & CODE EXAMPLE
 

CPP

if even number c++

#include <iostream>
using namespace std;

int main() {
  int n;

  cout << "Enter an integer: ";
  cin >> n;

  if ( n % 2 == 0)
    cout << n << " is even.";
  else
    cout << n << " is odd.";

  return 0;
}
Comment

check if a number is even or odd C++

// @Author: Subodh 
// 1 liner solution
(num & 1) ? cout << num << " is odd" : cout << num << " is even" << endl;
Comment

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
";
  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
";

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

  return 0;
}
Comment

how to find even and odd numbers in c++

#include<bits/stdc++.h>
using namespace std;

int main ()

{
    int x;
    cin >> x;
    if (x % 2 == 0) {
        cout << x << " " <<"is even number" endl;
    } else {
        cout << x << " " << "is odd number" endl;
        }

    return 0;
}
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ declaring and initializing strings 
Cpp :: how to read a comma delimited file into an array c++ 
Cpp :: c++ get time 
Cpp :: convert long int to binary string c++ 
Cpp :: qt disable resizing window 
Cpp :: how to run a msi file raspbrain 
Cpp :: parallelize for loop c++ 
Cpp :: character array to string c++ stl 
Cpp :: c++ find element in vector 
Cpp :: c++ declare variable 
Cpp :: sort stl 
Cpp :: c++ sort vector 
Cpp :: string reverse stl 
Cpp :: c++ iterate map 
Cpp :: search a word in cpp file 
Cpp :: const char to string 
Cpp :: find max value in array c++ 
Cpp :: check if character is uppercase c++ 
Cpp :: udo apt install dotnet-sdk-5 
Cpp :: how to get the first element of a map in c++ 
Cpp :: coordinate in 1d array 
Cpp :: file c++ 
Cpp :: c++ vectors 
Cpp :: lambda c++ 
Cpp :: back() in c++ 
Cpp :: opencv open image c++ 
Cpp :: how to reverse a string in c++ 
Cpp :: how to set a variable to infinity in c++ 
Cpp :: array to string c++ 
Cpp :: setw c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =