값의 비교 -switch,case
Switch 문
- if문은 한 번에 한가지 조건만 비교할 수 있는 데 반해,
switch문은 한 번에 여러 개의 조건을 비교할 수 있다.
Copy<형식>
switch (문장1)
{
case 값1 :
실행 블록1;
break;
case 값2 :
실행 블록2 ;
break;
...
case n :
실행 블록n;
break;
default :
실행 블록Default;
break;
}
/* 백준 1008번
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%.9f", (double)a / b);
return 0;
}
*/
/* 꼬마정민 11382번
#include <stdio.h>
int main() {
long long a, b, c;
scanf_s("%lld %lld %lld", &a, &b, &c);
printf("%lld", a+b+c);
return 0;
}
*/
/*
#include <stdio.h>
int main()
{
int A, B, C;
int a, b, c;
scanf("%d",&A);
scanf("%d", &B);
printf("%d\n", A * (B % 10));
printf("%d\n", A * (B % 100 - B % 10)/10);
printf("%d\n", A * (B - B % 100) / 100);
printf("%d\n", A * B);
return 0;
}
*/
'AI HW study > Baekjoon' 카테고리의 다른 글
백준 5단계 문자열 개념 정리 (0) | 2023.07.15 |
---|---|
백준 4단계: 1차원 배열 (0) | 2023.07.14 |
백준 3단계-2: 반복문 (0) | 2023.07.14 |
백준 10단계: 기하(직사각형과 삼각형) (0) | 2023.07.14 |
백준 3단계-1: 반복문 (0) | 2023.07.11 |