C++ program to check if a number is even or odd

Configurare noua (How To)

Situatie

To check if a given number is even or odd in C++, we simply divide the given number by 2, if the remainder is 0 then it is even otherwise odd.

Backup

#include <iostream>
using namespace std;
int main() {
int a ;
cin>>a;
if(a%2 == 0)  // if remainder is zero then even number
    cout<<”even”;
else       
    cout<<”odd”;
return 0;
}
Input: 8
Output: even

Solutie

Tip solutie

Permanent

Voteaza

(3 din 7 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?