Program to Check if a number is even or odd in C++

Configurare noua (How To)

Situatie

To Check if a given number is even or odd 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

(10 din 18 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?