본문 바로가기

Study/정보처리기사

C언어 Level 9

1~5. 다음 코드에 대한 출력 결과를 쓰시오.

 

1.

#include <stdio.h>
#define PI 3.14
int main() {
    printf("%.2f\n", PI);
    return 0;
}

 

2.

#include <stdio.h>
#define SQUARE(x) ((x) * (x))
int main() {
    int a = 5;
    printf("%d\n", SQUARE(a));
    return 0;
}

 

3.

#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main() {
    int x = 10, y = 20;
    printf("%d\n", MAX(x, y));
    return 0;
}

 

4.

#include <stdio.h>
#define PRINT_HELLO printf("Hello, World!\n")
int main() {
    PRINT_HELLO;
    return 0;
}

 

5.

#include <stdio.h>
#define DEBUG
int main() {
    #ifdef DEBUG
        printf("Debug mode is on\n");
    #else
        printf("Debug mode is off\n");
    #endif
    return 0;
}

 


 

정답
(드래그 시 정답이 보입니다.)

1. 3.14
2. 25
3. 20
4. Hello, World!
5. Debug mode is on

'Study > 정보처리기사' 카테고리의 다른 글

JAVA Level 1  (0) 2025.02.21
C언어 Level 10  (0) 2025.02.20
C언어 Level 8  (0) 2025.02.20
C언어 Level 7  (0) 2025.02.20
C언어 Level 6  (0) 2025.02.20