C Language if, else if, else Tutorial

In C language, conditional statements are usually implemented using the keywords if, else if, and else. Here is a simple example:

#include <stdio.h>

int main() {
    int num = 10;

    if (num > 0) {
        printf("%d是正数\n", num);
    } else if (num < 0) {
        printf("%d是负数\n", num);
    } else {
        printf("%d是零\n", num);
    }

    return 0;
}

In the example above, if num is greater than 0, print “10 is a positive number”; if num is less than 0, print “10 is a negative number”; otherwise, print “10 is zero”. The program will execute different code blocks based on the condition.

bannerAds