Sunday, 14 November 2010

write a program to find the average, grade of the 3 subjects using switch case

#include<stdio.h>
#include<conio.h>
void main()
{
 int rno, m,p,c,tot,k;
 float avg;
 char *grade;
 char sname[20];
 clrscr();
 printf("enter roll no\n");
 scanf("%d", &rno);
 printf("enter name\n");
 fflush(stdin);
 gets(sname);
 printf("enter 3 subjects marks\n");
 scanf("%d%d%d",&m,&p,&c);
 tot=m+p+c;
 avg=(float)tot/3;
 if(m<40||p<40||c<40)
  grade="fail";
 else
{
  k=avg/10;
 switch(k)
 {
   case 7:
   case 8:
   case 9:
   case 10:
                {
     grade="distinction";
     break;
              }
  case 6:
  {
     
     grade="first class";
     break;
  }
  case 5:{
     grade="2nd class";
     break;
          }
   case 4:{
     grade="3rd class";
     break;
             }
}//end of switch
}//end of else

  printf("total marks are=%d\n",tot);
 printf("Average=%.2f\n",avg);
 printf("grade=%s\n",grade);
getch();
}

Conditional statements

      

No comments:

Post a Comment