If then else

if(boolean_expression 1) {
   /* Executes when the boolean expression 1 is true */
}
else if( boolean_expression 2) {
   /* Executes when the boolean expression 2 is true */
}
else if( boolean_expression 3) {
   /* Executes when the boolean expression 3 is true */
}
else  {
   /* executes when the none of the above condition is true */
}

Ví dụ: in những số lẻ từ 0 đến 20

#include <stdio.h>

int main() {
    for (int i = 0; i < 20; i++) {
        if (i % 2 == 1) {
            printf("%d\n", i);
        }
    }
    return 0;
}

In số lẻ chia hết cho 3 nhưng không chia hết cho 5

if ((i % 2 == 1) && (i % 3 == 0) && !(i % 5 ==0)) {
   printf("%d\n", i);
}

Toán tử Boolean

AND

if (expression1 && expression2) {

}

OR

results matching ""

    No results matching ""