Saturday, January 30, 2010

CHAP 4[D] Case Control Structure (using switch)

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


void main()
{
int c,s;
printf("\nEnter the class obtained by the student and the number of subjects he has failed in");
scanf("%d%d",&c,&s);

switch(c)
{
case 1:
switch(s>3)
{
case 1:
printf("\nNo grace");
break;
case 0:
printf("\nGrace of 5 marks per subject");
break;
}
break;

case 2:
switch(s>2)
{
case 1:
printf("\nNo grace");
break;
case 0:
printf("\nGrace of 4 marks per subject");
break;
}
break;

case 3:
switch(s>1)
{
case 1:
printf("\nNo grace");
break;
case 0:
printf("\nGrace of 5 marks per subject");
break;
}
break;
}
}

3 comments:

  1. can u tell me how can i get solutions of let us c 8th ed by yashwant kanethkar

    ReplyDelete
    Replies
    1. not possible to get hard copy...

      Delete
  2. from where should i get let us c 5th solution plzzz helpp....thanks in advance

    ReplyDelete