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

1 Answer

0 votes
#include <stdio.h>
#include <stdbool.h>

bool is_even(int n) { 
    return ((n / 2) * 2 == n); 
} 
  
int main() {
    int n = 13; 
     
    is_even(n) ? printf("Even") : printf("Odd"); 
}


/*
run:

Odd

*/

 



answered Mar 27, 2019 by avibootz
...