#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;
}
#include<iostream>
using namespace std;
int main()
{
do
{
int num, even = 0, odd = 0;
for (int i = 0; i < 8; i++)
{
cin >> num;
if (num % 2 == 0)
even += num;
else
odd += num;
}
cout << "Even: " << even << endl;
cout << "Odd: " << odd << endl;
} while (true);
return 0;
}
// @Author: Subodh
// 1 liner solution
(num & 1) ? cout << num << " is odd" : cout << num << " is even" << endl;
#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;
}
#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;
}
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter an integer: ";
cin >> n;
(n % 2 == 0) ? cout << n << " Is Even." : cout << n << " Is 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;
}
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int inp;
cin>>inp;
if(inp % 2 == 0)
{
cout<<" Even" <<endl;
}
else
{
cout<<"Odd"<<endl;
}
}
#include <iostream>
using namespace std;
int main() {
int x;
cout << "Enter a number:";
cin >> x;
if (x%2==0)
{
cout <<x<<" is an EVEN number.";
}
else
{
cout <<x<<" is an ODD number.";
}
return 0;
}
Code Example |
---|
Cpp :: how to add space in c++ |
Cpp :: polymorphism in c++ |
Cpp :: accumulate vector c++ |
Cpp :: how to make a function in c++ |
Cpp :: tuple vector c++ |
Cpp :: c++ constructor call superclass |
Cpp :: c++ data types |
Cpp :: looping in map c++ |
Cpp :: find pair with given sum in the array |
Cpp :: put text on oled |
Cpp :: initialising 2d vector |
Cpp :: loop c++ |
Cpp :: QVariant to int |
Cpp :: draw line sfml |
Cpp :: how to reset linerenderer unity |
Cpp :: c++ comment out multiple lines |
Cpp :: Operators in C / C++ |
Cpp :: input c++ |
Cpp :: c++98 check if character is integer |
Cpp :: max heap insertion c++ |
Cpp :: unordered_map c++ |
Cpp :: runtime |
Cpp :: queue operations c++ |
Cpp :: Program to find GCD or HCF of two numbers c++ |
Cpp :: declare class c++ |
Cpp :: convert uppercase to lowercase |
Cpp :: c++ bit shift wrap |
Cpp :: c++ include difference between quotes and brackets |
Cpp :: short int range in c++ |
Cpp :: Bit Tricks for Competitive Programming c ++ |