#include <stdio.h>

int main() {
    /* 논리 연산자
        && : AND 양쪽 모두 참이면 참
        || : OR 둘 중 하나 이상 참이면 참
        ! : NOT 참과 거짓을 반대로 
        C언어에서는 참을 1, 거짓을 0으로 취급한다
    */
    int a = 5, b = 10, c = 15;

    printf("%d\n", a > 3 && b > 5);
    printf("%d\n", a < 3 || c == 15);
    printf("%d\n", !(a == 5));

    printf("%d\n", a + b > c && c == 15);
    printf("%d\n", a + (b > c));


    /* 연산자 우선순위
        1. 괄호()
        2. 단항 연산자 ! ++ --
        3. 산술 연산자 * / % -> + -
        4. 비교 연산자 < > <= >= == !=
        5. 논리 연산자 && -> ||
        6. 대입 연산자 = += -=
    */

    printf("----문제----\n");
    // 문제 : 아래 식에서 연산 순서를 적으시오
    printf("%d\n", a + b > c && c == 15);
    //               1   2   4    3
    printf("%d\n", a * b + c > b || a == 5);
    //               1   2   3    5   4
    printf("%d\n", !(a + b <= c) && b != 10);
    //             3   1    2     5    4

int x = 7, y = 12;
    printf("%d\n", 5 * x + y > 20 && 30 == y);
//                   1    2   3    5     4     

printf("%d\n", (x + y) * 2 <= 50 || 40 - y == x);
//                1     2     4   7    5    6

printf("%d\n", !(x + y > 10 || x * y < 50) && y != 15);
//             6    2    3   4    1    5    6    7
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: