여러 결정 중 하나를 선택하는 데 사용됩니다. 'switch'는 정수(또는) 문자 상수 목록에 대해 값을 연속적으로 테스트합니다. 일치하는 항목이 발견되면 해당 값과 관련된 문(또는) 문을 실행합니다.
구문
구문은 다음과 같습니다 -
switch (expression){
case value1 : stmt1;
break;
case value2 : stmt2;
break;
- - - - - -
default : stmt – x;
} 알고리즘
아래 주어진 알고리즘을 참조하십시오 -
Step 1: Declare variables. Step 2: Read expression variable. Step 3: Switch(expression) If value 1 is select : stmt 1 executes break (exists from switch) If value 2 is select : stmt 2 executes ;break If value 3 is select : stmt 3 executes; break …………………………………………… Default : stmt-x executes;

예시
다음 C 프로그램은 switch 문의 사용법을 보여줍니다 -
#include<stdio.h>
main ( ){
int n;
printf ("enter a number");
scanf ("%d", &n);
switch (n){
case 0 : printf ("zero");
break;
case 1 : printf ("one");
break;
default : printf ("wrong choice");
}
} 출력
다음 출력이 표시됩니다 -
enter a number 1 One
아래에 언급된 스위치 케이스에 대한 다른 프로그램을 고려하십시오 -
예시
#include<stdio.h>
int main(){
char grade;
printf("Enter the grade of a student:\n");
scanf("%c",&grade);
switch(grade){
case 'A': printf("Distiction\n");
break;
case 'B': printf("First class\n");
break;
case 'C': printf("second class \n");
break;
case 'D': printf("third class\n");
break;
default : printf("Fail");
}
printf("Student grade=%c",grade);
return 0;
} 출력
다음 출력이 표시됩니다 -
Run 1:Enter the grade of a student:A Distiction Student grade=A Run 2: Enter the grade of a student:C Second class Student grade=C