Sunday, 14 November 2010

write a program to find the average, grade of the 3 subjects using if ..else

#include<stdio.h>
#include<conio.h>
void main()
{
 int rno, m,p,c,tot;
 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 if(avg>=70)
     grade="distinction";
   else if(avg>=60)
     grade="first class";
   else if((avg>=50)
     grade="2nd class";
  else
     grade="3rd class";
  printf("total marks are=%d\n",tot);
 printf("Average=%.2f\n",avg);
 printf("grade=%s\n",grade);
getch();
}


      Else if

No comments:

Post a Comment