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

1 Answer

0 votes
#include <iostream>

int main() {
    const int n = 10;

    (n % 2 == 0) ? std::cout << "Even" : std::cout << "Odd";
}

    
/*
run:
    
Even
    
*/

 



answered Sep 17, 2024 by avibootz

Related questions

...