Program:
#include<stdio.h>
#include<conio.h>
int mark(int,int);
void main()
{
int four,three,two,five,m4,m3,m2,m1,tot,totm;
float gpa;
clrscr();
printf("\nHow many Sub has 'credit 5': ");
scanf("%d",&five);
printf("\nHow many Sub has 'credit 4': ");
scanf("%d",&four);
printf("\nHow many Sub has 'credit 3': ");
scanf("%d",&three);
printf("\nHow many Lab Subjects: ");
scanf("%d",&two);
tot=(4*four)+(3*three)+(2*two)+(5*five);
m4=mark(4,four);
m3=mark(3,three);
m2=mark(2,two);
m1=mark(5,five);
totm=m4+m3+m2+m1;
gpa=(float)totm/tot;
printf("\n\n *********************** \n");
printf("* *\n");
printf("* Your GPA is: %f *\n",gpa);
printf("* *\n");
printf(" ***********************");
getch();
}
int mark(int grade,int num)
{
int j=1,n,c;
float i=0;
char ma;
c=0;
while(c<num)
{
fflush(0);
clrscr();
label_a:
printf("\nEnter the Grade you scored in the \n");
printf(" 'subject Number-%d' of credit '%d'= ",j,grade);
scanf("%c",&ma);
fflush(0);
switch(ma)
{
case 'S': { n=10; break; }
case 's': { n=10; break; }
case 'A': { n=9; break; }
case 'a': { n=9; break; }
case 'B': { n=8; break; }
case 'b': { n=8; break; }
case 'C': { n=7; break; }
case 'c': { n=7; break; }
case 'D': { n=6; break; }
case 'd': { n=6; break; }
case 'E': { n=5; break; }
case 'e': { n=5; break; }
default: { printf("\nEnter a valid grade\n");
goto label_a;
}
}
i=i+(grade*n);
c++;
j++;
}
return i;
}
Sample Output:
#include<stdio.h>
#include<conio.h>
int mark(int,int);
void main()
{
int four,three,two,five,m4,m3,m2,m1,tot,totm;
float gpa;
clrscr();
printf("\nHow many Sub has 'credit 5': ");
scanf("%d",&five);
printf("\nHow many Sub has 'credit 4': ");
scanf("%d",&four);
printf("\nHow many Sub has 'credit 3': ");
scanf("%d",&three);
printf("\nHow many Lab Subjects: ");
scanf("%d",&two);
tot=(4*four)+(3*three)+(2*two)+(5*five);
m4=mark(4,four);
m3=mark(3,three);
m2=mark(2,two);
m1=mark(5,five);
totm=m4+m3+m2+m1;
gpa=(float)totm/tot;
printf("\n\n *********************** \n");
printf("* *\n");
printf("* Your GPA is: %f *\n",gpa);
printf("* *\n");
printf(" ***********************");
getch();
}
int mark(int grade,int num)
{
int j=1,n,c;
float i=0;
char ma;
c=0;
while(c<num)
{
fflush(0);
clrscr();
label_a:
printf("\nEnter the Grade you scored in the \n");
printf(" 'subject Number-%d' of credit '%d'= ",j,grade);
scanf("%c",&ma);
fflush(0);
switch(ma)
{
case 'S': { n=10; break; }
case 's': { n=10; break; }
case 'A': { n=9; break; }
case 'a': { n=9; break; }
case 'B': { n=8; break; }
case 'b': { n=8; break; }
case 'C': { n=7; break; }
case 'c': { n=7; break; }
case 'D': { n=6; break; }
case 'd': { n=6; break; }
case 'E': { n=5; break; }
case 'e': { n=5; break; }
default: { printf("\nEnter a valid grade\n");
goto label_a;
}
}
i=i+(grade*n);
c++;
j++;
}
return i;
}
Sample Output:
No comments:
Post a Comment
Let Us hear Your thoughts about this Post.. Its Our Pleasure to get your feedback..