Friday, 4 December 2015

AVERAGE MARK AND GRADE OF STUDENTS

AIM
To write a C program to calculate the average mark and grade of students using switch.
ALGORITHM
Step 1: Start
Step 2: Read n, m1, m2, m3, m4, m5, iß0
Step 3: if (i<n), if not go to step 19
Step 4: avgß(m1+m2+m3+m4+m5)/5
Step 5: iß(i+1), avg1ß(avg*100)
Step 6: if (avg1>90), if not go to step 8
Step 7: Print Grade A, avg, go to step 18
Step 8: if (avg1>80), if not go to step 10
Step 9: Print Grade B, avg, go to step 18
Step 10: if (avg1>70), if not go to step 12
Step 11: Print Grade C, avg, go to step 18
Step 12: if (avg1>60), if not go to step 14
Step 13: Print Grade D, avg, go to step 18
Step 14: if (avg1>50), if not go to step 16
Step 15: Print Grade E, avg, go to step 18
Step 16: if (avg1<=50)
Step 17: Print Grade F, avg
Step 18: Go to step 3
Step 19: Stop
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
    float m1,m2,m3,m4,m5,avg;
    int grade;
    printf("Enter mark of 5 subjects\n");
    scanf("%f%f%f%f%f",&m1,&m2,&m3,&m4,&m5);
    avg=(m1+m2+m3+m4+m5)/3;
    printf("Average = %f\n",avg);
    if(avg>=85)
        grade=1;
    else if(avg>=70)
        grade=2;
    else if(avg>=60)
        grade=3;
    else if(avg>=50)
        grade=4;
    else if(avg>=40)
        grade=5;
    else
        grade=6;
    switch(grade)
    {
    case 1:
        printf("grade is A");
        break;
    case 2:
        printf("grade is B");
        break;
    case 3:
        printf("grade is C");
        break;
    case 4:
 printf("grade is D");
    case 5:
        printf("grade is E");
        break;
    case 6:
        printf("FAIL");
        break;
    }
    getch();

}

No comments:

Post a Comment