How to check odd or even using conditional (ternary) operator in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    const int n = 10;
    
    (n % 2 == 0) ? printf("Even\n") : printf("Odd\n");

    return 0;
}


/*
run:
    
Even
    
*/


answered May 11, 2015 by avibootz
edited Sep 17, 2024 by avibootz
...