How to check if a number is odd or even without modulus operator in C++

1 Answer

0 votes
#include <iostream>

using namespace std;
  
bool is_even(int n) { 
    return ((n / 2) * 2 == n); 
} 
  
int main() 
{ 
    int n = 13; 
    
    is_even(n) ? cout << "Even" : cout << "Odd"; 
    
    return 0; 
} 



/*
run:
  
Odd
  
*/

 



answered Mar 27, 2019 by avibootz

Related questions

...