Switch Case statement is use to build decision making programs.
Like if-else, switch case is also a decision-making structure. Furthermore, it can help to make decision-making programs.
For example, if you want to make a grading system program.
In which
90-99- Grade A
80-89- Grade B
70-79- Grade C
60-69- Grade D
50-59- Grade E
Less than 50- Fail
#include<stdio.h>
void main()
{
int marks, grade;
printf(“Enter the marks”, &marks);
if( marks>100 || marks< 0)
{
printf(“Enter valid marks score”)
} else {
scanf(“%d”,&marks);
}
grade= marks/10;
switch(grade) {
case 9:
printf(“Grade A”);
break ;
case 8:
printf(“Grade B”);
break ;
case 7:
printf(“Grade C”);
break ;
case 6:
printf(“Grade D”);
break ;
case 5:
printf(“Grade E”);
break ;
default:
printf(“Fail”);
break ;
}
}
Submit Guest Post To Blog
[user-submitted-posts]