Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

odd even in c with ternary operator

#include <stdio.h>
int main() {
    int num;
    printf("Enter an integer: ");
    scanf("%d", &num);
    // true if num is perfectly divisible by 2
   num % 2 == 0 ? printf("%d is even.", num); :  printf("%d is odd.", num);
    return 0;
}
 
PREVIOUS NEXT
Tagged: #odd #ternary #operator
ADD COMMENT
Topic
Name
7+7 =