switch statement c example
Example 1: switch statement in c
#include <stdio.h>
int main(void)
{
int a = 0;
switch(a)
{
case 1 :
statement("a = 1");
break;
case 2 :
printf("a = 2");
break;
default :
printf("a is neither 1 or 2");
break;
}
}
Example 2: switch c
int main(){
int n;
printf("choose one of those numbers (1, 2, 3)";
fflush("stdin");
switch(n){
case 1:
//do something if n = 1
break;
case 2:
//do something if n = 2
break;
case 3:
//do something if n = 3
break;
default:
printf("holy moly you suck");
}
return 0;