Sunday, August 15, 2010

2 d array of character type program to demonstrate students grade


Here is another program on C Language character type array. Accept name of the students and exam grade of each student, determine an average grade for each student, and display name, the individual exam grade, the calculated average and the rank for each student.


   #include< stdio.h >
   #include< string.h >
   void main()
   {
   char name[4][30];
   char grade[20],c,dummy[30];
   int i,j,t=0;
   clrscr();
   printf("If the mark is >=80 put 'A',>= 65 but <80\n");
   printf("put 'B' grade.Marks <65, put 'C' grade\n");
    for(i=0;i< 4;i++)
    {
    puts("\nEnter the name:-");
    gets(name[i]);
    puts("\nEnter the GRADE:-");
    c=getchar();
    c=toupper(c);
    grade[i]=c;
    fflush(stdin);
    }
   grade[i]=NULL;
   for(i=0;i< 4;i++)
    {
     for(j=i+1;j <4;j++)
      {
       if(grade[i] >grade[j])
            {
             c=grade[i];
             grade[i]=grade[j];
             grade[j]=c;
             strcpy(dummy,name[i]);
             strcpy(name[i],name[j]);
             strcpy(name[j],dummy);
             }
            }
       }
   puts("\nPress any KEY to see the Result.......");
   getch();
  for(i=0;i< 4;i++)
  {
   printf("%s   %c\n",name[i],grade[i]);
  }
  for(i=0;I <4;i++)
  {
   if(grade[i]=='A')
    t=t+80;
    else if(grade[i]=='B')
    t=t+65;
    else
    t=t+64;
   }
   t=t/4;
   if(t>=80)
   printf("\nAverage grade is 'A'");
   else if(t>=65)
   printf("\nAverage grade is 'B'");
   else
   printf("\nAverage grade is 'C'");
 getch();
 }



No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner