Ternary operator and if statement

Operator (ternary operator)

#include<stdio.h>
int main(void)
{
    
    
    int num;
    printf("输入一个数字 : ");
    scanf("%d",&num);
    (num%2==0)?printf("偶数"):printf("奇数");
    return 0;
}

Insert picture description here
This uses a ternary operator to determine odd and even numbers.
The block diagram is as follows:

Insert picture description here
Let's look at the if statement to determine odd and even numbers.

#include<stdio.h>
int main(void)
{
    
    
    int num;
    printf("输入一个数字 : ");
    scanf("%d",&num);
   if (num%2==0)
   printf("偶数");
   else
   printf("奇数");
    return 0; 
}

Insert picture description here
if statement An if statement consists of a Boolean expression followed by one or more statements .

Insert picture description here

Please correct me if I have been exposed to the wrong part of the c language recently.
Leave your footsteps below.
(﹡ˆOˆ﹡)

Guess you like

Origin blog.csdn.net/qq_51932922/article/details/112970952