Monday, 5 August 2013

Chapter 4 solutions Problem [D]

Question-Write a 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. 
−  If the student gets first class and the number of subjects he 
failed in is greater than 3, then he does not get any grace. 
If the number of subjects he failed in is less than or equal 
to 3 then the grace is of 5 marks per subject. 
−  If the student gets second class and the number of subjects 
he failed in is greater than 2, then he does not get any 
grace. If the number of subjects he failed in is less than or 
equal to 2 then the grace is of 4 marks per subject. 
−  If the student gets third class and the number of subjects 
he failed in is greater than 1, then he does not get any 
grace. If the number of subjects he failed in is equal to 1 
then the grace is of 5 marks per subject 

solution- very easy and boring as well, i except every beginner can write this but just for the sake of completeness of the program.

#include<stdio.h>
int main()
{
int class,fail;
printf("Enter the class you obtained and number of subject you failed in\n");
scanf("%d%d",&class,&fail);
switch(class)
{
case 1:
if(fail>3)
printf("You won't get any grace\n");
else
printf("You will get the grace of 5 marks per subject\n");
break;
case 2:
if(fail>2)
printf("you won't get any grace at all\n");
else
printf("You would get the grace of 4 marks per subject\n");
break;
case 3:
if(fail>1)
printf("you won't get any grace\n");
else
printf("you would get the grace of 5 marks in one subject\n");
}
return 0;
}









No comments:

Post a Comment