case en c code example
Example 1: switch c
int main(){
int n;
printf("choose one of those numbers (1, 2, 3)";
fflush("stdin");
switch(n){
case 1:
break;
case 2:
break;
case 3:
break;
default:
printf("holy moly you suck");
}
return 0;
Example 2: switch case c
switch (expression) {
case constant1:
break;
case constant2:
break;
default:
}
Example 3: switch case in c
#include <stdio.h>
int main() {
char operator;
double n1, n2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%lf %lf",&n1, &n2);
switch(operator)
{
case '+':
printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
break;
default:
printf("Error! operator is not correct");
}
return 0;
}
Example 4: switch c
switch (n)
{
case 1:
break;
case 2:
break;
default:
}