Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

문타쿠, 공부하다.

[C언어 코딩 도장] Unit 19. 연습문제 및 심사문제 본문

C언어/C언어 코딩 도장

[C언어 코딩 도장] Unit 19. 연습문제 및 심사문제

개발새발 문타쿠 2023. 8. 24. 18:02

19.4 연습문제: if, else if, else를 모두 사용하기

#include <stdio.h>

int main(void)
{
	char c1 = 'c';

	if (c1 == 'a')
		printf("a\n");
	else if (c1 == 'b')
		printf("b\n");
	else if (c1 == 'c')
		printf("c\n");
	else if (c1 == 'd')
		printf("d\n");
	else
		printf("x\n");

	return 0;
}

19.5 심사문제: 교통카드 시스템 만들기

#include <stdio.h>

int main(void)
{
	int balance = 10000;
	int age;

	scanf_s("%d", &age);

	if (age >= 7 && age <= 12)
		balance = balance - 450;
	else if (age >= 13 && age <= 18)
		balance = balance - 720;
	else if (age >= 19)
		balance = balance - 1200;

	printf("%d\n", balance);

	return 0;
}