Monday 17 September 2012

Find students grades through structure


Before writing program we make some assumption as following :

Maximum total marks is 500.    
  Student_percentage         Grades
     >=80                        A
     >=60                        B
     >=50                        C
     >=40                        D
     <40                         F
 
/*C program to find students grades in a class through structure */
#include<stdio.h>
#include<conio.h>
struct stud
{
  char nam[20];
  int obtain_mark;
  int per;
  char grad[5];
};
struct stud s[5];
int i;
int main()
{
 for(i=1; i<=5; i++)
 {
  printf("Enter %d student name : ",i);
  scanf("%s",&s[i].nam);
  printf("Enter %d student obtained marks = ",i);
  scanf("%d",&s[i].obtain_mark);
  fflush(stdin);
 }
 for(i=1; i<=5; i++)
   s[i].per=s[i].obtain_mark/5;
 for(i=1; i<=5; i++)
 {
  if(s[i].per>=80)
    strcpy(s[i].grad,"A");
  else if(s[i].per>=60)
    strcpy(s[i].grad,"B");
  else if(s[i].per>=50)
    strcpy(s[i].grad,"C");
  else if(s[i].per>=40)
    strcpy(s[i].grad,"D");
  else
    strcpy(s[i].grad,"F");
 }

No comments:

Post a Comment