switch case :
It provides a multi way branching. It allows user to select any one of the several alternatives, depending upon the value of an expression. The value of expression enclosed with in the parentheses. Depending upon the value of expression,the control is transferred to a particular case and statements executed according to the case value.The syntax of switch statement is
SYNTAX
:
switch(expression)
{
case value 1: statement
1;
break;
case value 2: statement 2;
break;
case value 3: statement
3;
break;
case default: statement
n;
break;
}
}
EXAMPLE
:
#include<stdio.h>
void
main( )
{
int num;
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
switch(num)
{
case 1: printf(" UNITED
STATES ");
{
int num;
printf("Hello user, Enter a number");
scanf("%d",&num); // Collects the number from user
switch(num)
{
case 1: printf("
case 2: printf("
case 3: printf("
default: printf("
}
}