elibraryportal Logo

Switch statement in C

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

Syntax:

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:

Output

Switch statement Example

Example 2:

Output

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

Example 3:

Output

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

Example 4: calculator Program

Output

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