Wednesday, May 11, 2016

Calculate GPA Of Five Subjects.





#include <stdio.h>
int xyz (int);
int main ()
{
    int m1,m2,m3,m4,m5,c1,c2,c3,c4,c5;
    int gp1,gp2,gp3,gp4,gp5,tc;
    float tgp,gpa;
   
    printf("Enter Marks Of Subject 1:\n");
    scanf("%d",&m1);
    gp1=xyz(m1);
    printf("Enter Credit hOurs Of Subject 1\n");
    scanf("%d",&c1);
     printf("Enter Marks Of Subject 2:\n");
    scanf("%d",&m2);
    gp2=xyz(m2);
    printf("Enter Credit hOurs Of Subject 2\n");
    scanf("%d",&c2);
     printf("Enter Marks Of Subject 3:\n");
    scanf("%d",&m3);
    gp3=xyz(m3);
    printf("Enter Credit hOurs Of Subject 3\n");
    scanf("%d",&c3);
     printf("Enter Marks Of Subject 4:\n");
    scanf("%d",&m4);
    gp4=xyz(m4);
    printf("Enter Credit hOurs Of Subject 4\n");
    scanf("%d",&c4);
     printf("Enter Marks Of Subject 5:\n");
    scanf("%d",&m5);
    gp5=xyz(m5);
    printf("Enter Credit hOurs Of Subject 5\n");
    scanf("%d",&c5);
   
    tgp=(gp1*c1)+(gp2*c2)+(gp3*c3)+(gp4*c4)+(gp5*c5);
    tc=c1+c2+c3+c4+c5;
    gpa=tgp/tc;
    printf("GPA=%.1f",gpa);
}
int xyz (int m)
{
int y,gp;
y=m/10;
    switch (y)
    {
        case 10:
        case 9:
        case 8:
        gp=4;
        break;
        case 7:
        gp=3;
        break;
        case 6:
        gp=2;
        break;
        case 5:
        gp=1;
        break;
        case 4:
        case 3:
        case 2:
        case 1:
        gp=0;
        break;
        default:
 
        break;
   }
   return gp;
}



Share this

0 Comment to "Calculate GPA Of Five Subjects."

Post a Comment