elibraryportal Logo

Switch statement in C

switch statement is used to execute the code from multiple conditions depending on the value of an expression


Note:- wehre expression refers any int or char expression or vaiable. <label1>,<label2><labeln> are values which will match with the value of the expression. brak is satement which will transfer the control to the end of switch statement.

Example 1:


Switch statement Example

Example 2:


    Enter any number (1 to 7): 5 Today is Friday

Example 3:


    Enter any number (1 to 7): 4 Today is Thursday Today is Friday Today is Saturday Today is Sunday

Example 4: calculator Program


 Enter First number: 6
Enter operator : +
Enter Second number: 10
Sum: 16