SWITCH CASE CONTROL STATEMENT IN C
Flow chart of Switch case:-
<<< Rules for Switch Statement >>>
1. switch expression must be int or char.
2. case value must be an integer or a character.
3. case must come inside switch.
4. break is not a must.
#include <stdio.h>
int main(int argc, char const *argv[])
{
int age;
printf("Enter your age\n");
scanf("%d",&age);
switch (age)
{
case 13:
printf("The age is 13");
break;
case 20:
printf("The age is 20");
break;
case 24:
printf("The age is 24");
break;
default:
printf("Age is not 13,20 and 24");
break;
}
return 0;
}
we can add switch statement inside the switch statement
Examples:----
#include <stdio.h>
int main(int argc, char const *argv[])
{
int age;
int marks;
printf("Enter your age\n");
scanf("%d", &age);
printf("Enter your marks\n");
scanf("%d", &marks);
switch (age)
{
case 3:
printf("The Age is 3\n");
switch (marks)
{
case 45:
printf("marks are 45\n");
break;
default:
printf("your marks are not 45 ");
break;
}
break;
case 7:
printf("The Age is 7\n");
switch (marks)
{
case 78:
printf("Marks are 78");
break;
default:
printf("Your marks are not 78");
break;
}
break;
default:
printf("Age not match");
break;
}
return 0;
}