switch mode c programming

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

showing results for - "switch mode c programming"
Gianluca
27 Nov 2020
1//A switch statement allows a variable to be 
2//tested for equality against a list of values.
3
4#include <stdio.h>
5
6int mode = 2; 
7
8int main() {
9  //switch takes argument and gives cases for it. 
10    switch (mode) {
11        //each case has a value for which it tests... 
12        case 1: 
13            //Your code goes here... 
14            
15            printf("This is mode #1.\n"); 
16        //each case must have break otherwise code will fall 
17        //through into next case. This is good for some things 
18        //like testing multiple case at once on the same value, though. 
19        break; 
20        case 2: 
21            //Your code goes here... 
22            
23            printf("This is mode #2\n"); 
24        break; 
25        case 3: 
26            //Your code goes here... 
27            
28            printf("This is mode #3.\n"); 
29        break; 
30    }
31	return 0;
32}