You are here:   HomeC Programming (Theory)Control Structures in CWrite a C program which to find the grace marks for a student using switch. The user should enter the class obtained by the student and the number of subjects he has failed in.
by Dinesh Thakur Category: Control Structures

 

 

#include<stdio.h>

#include<conio.h>
void main()
{
int c,sub;
clrscr();
printf("Enter the class and number of subjects failed:");
scanf("%d%d",&c,&sub);
switch(c)
{
case 1:
if(sub>=1&&sub<=3)
printf("\nStudent gets total of %d grace marks",5*sub);
else
if(sub>3)
printf("\nNo grace marks");
break;
case 2:
if(sub>=1&&sub<=2)
printf("\nStudents gets total of %d grace marks",4*sub);
else
if(sub>2)
printf("\nNo grace marks");
break;
case 3:
if(sub==1)
printf("\nStudent gets 5 grace marks");
else
if(sub>1)
printf("\nNo grace marks");
break;
default:
printf("\nWrong class entered ");
}
printf("\nPress any key to exist…”);
getch();
}


Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article