날짜

<aside> <img src="/icons/calendar_gray.svg" alt="/icons/calendar_gray.svg" width="40px" />

2025.01.09. 19 : 00 - 21 : 00

</aside>

계획

활동내용

1 제어문

1.1 조건문

1.1.1 단순 if 문

#include <stdio.h>

int main(void) {
		int num;
		scanf("%d", &num);
		if (num < 10) {
				printf("10보다 작습니다.\\n");
		}
		return 0;
}

1.1.2 if - else 문

#include <stdio.h>

int main(void) {
		int num;
		scanf("%d", &num);
		if (num % 2 == 0) {
				printf("짝수입니다.\\n");
		}
		else {
				printf("홀수입니다.\\n");
		}
		return 0;
}

1.1.3 if - else if - else 문

#include <stdio.h>

int main(void) {
    int score;
    scanf("%d", &score);
 
    if (score >= 90) {
        printf("A학점\\n");
    }
    else if (score >= 80) {
        printf("B학점\\n");
    }
    else if (score >= 70) {
        printf("C학점\\n");
    }
    else if (score >= 60) {
        printf("D학점\\n");
    }
    else {
        printf("F학점\\n");
		}
    return 0;
}

1.1.4 switch 문

#include <stdio.h>
 
int main(void)
{
    int menu;
    printf("1.치킨  2.피자  3.떡볶이  4.햄버거\\n");
    printf("원하는 메뉴를 선택하세요. : ");
    scanf("%d", &menu);
 
    switch (menu)
    {
    case 1:
        printf("치킨을 선택했습니다.\\n");
        break;
    case 2:
        printf("피자를 선택했습니다.\\n");
        break;
    case 3:
        printf("떡볶이를 선택했습니다.\\n");
        break;
    case 4:
        printf("햄버거를 선택했습니다.\\n");
        break;
    default:
        printf("잘못 입력하였습니다.\\n");
    }
    return 0;
}

1.2 반복문

1.2.1 for 문

#include <stdio.h>
 
int main(void) {
    int num = 1;
    int i;
 
    for (i = 0; i < 3; i++) {
        num *= 2;
    }
    printf("%d", num);
    return 0;
}

1.2.2 while 문

#include <stdio.h>

int main(void) {
    int num = 0;
 
    while (num < 5) {
        printf("Hello, world!\\n");
        num++;
    }
    return 0;
}

1.2.3 do - while 문

#include <stdio.h>
 
int main(void) {
    int pw = 1234;
    int inputpw = 0;
 
    do {
        printf("비밀번호를 입력하세요. : ");
        scanf("%d", &inputpw);
    } while (pw != inputpw);
 
    printf("확인되었습니다.\\n");
    return 0;
}

1.3 기타 제어문