c switch case

Solutions on MaxInterview for c switch case by the best coders in the world

showing results for - "c switch case"
Manuel
23 Nov 2016
1switch (n)
2{
3    case 1: // code to be executed if n = 1;
4        break;
5    case 2: // code to be executed if n = 2;
6        break;
7    default: // code to be executed if n doesn't match any cases
8}
Penelope
23 Jan 2020
1#include <stdio.h>
2
3int main(void)
4{
5  	int a = 0;
6  
7    switch(a)
8    {
9       case 1 :
10          statement("a = 1");
11          break;
12
13       case 2 :
14          printf("a = 2");
15          break;
16
17       default :
18       	  printf("a is neither 1 or 2");
19	      break;
20    }
21}
Nico
02 Jul 2019
1switch (expression) {
2    case constant1:
3      // statements
4      break;
5
6    case constant2:
7      // statements
8      break;
9
10    default:
11      // default statements
12}
Stefania
13 Oct 2018
1int i;
2
3switch (i){
4  case 1:
5    	//The Proccess you want to be executed
6    	break;
7  case 2:
8    	//The Proccess you want to be executed
9   		break;
10  default:
11    	break;
12}
Garry
12 Jul 2020
1// example of switch case statement
2#include <stdio.h>
3
4int main() {
5    char operator;
6    double n1, n2;
7
8    printf("Enter an operator (+, -, *, /): ");
9    scanf("%c", &operator);
10    printf("Enter two operands: ");
11    scanf("%lf %lf",&n1, &n2);
12
13    switch(operator)
14    {
15        case '+':
16            printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
17            break;
18
19        case '-':
20            printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
21            break;
22
23        case '*':
24            printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
25            break;
26
27        case '/':
28            printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
29            break;
30
31        // operator doesn't match any case constant +, -, *, /
32        default:
33            printf("Error! operator is not correct");
34    }
35
36    return 0;
37}
38
Emilia
03 Jul 2019
1int main(){
2	int n;
3    printf("choose one of those numbers (1, 2, 3)";
4    fflush("stdin");
5    switch(n){
6    
7   	case 1:
8    
9    	//do something if n = 1
10    	break;
11    
12    case 2:
13    
14    	//do something if n = 2
15    	break;
16    case 3:
17    	//do something if n = 3
18    	break;
19        
20	default:
21    
22    	printf("holy moly you suck");
23	}
24    return 0;
similar questions
queries leading to this page
c switch case