Ans.
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");
}
for(i=1; i<=5; i++)
printf("\n%d student %s has obtained grade %s ",i,s[i].nam,s[i].grad);
getch();
return 0;
}
Output:
Enter 1 student name : John
Enter 1 student obtained marks : 250
Enter 2 student name : Robert
Enter 2 student obtained marks : 410
Enter 3 student name : Isabell
Enter 3 student obtained marks : 386
Enter 4 student name : Adem
Enter 4 student obtained marks :197
Enter 5 student name :Harry
Enter 5 student obtained marks : 490
1 student Jhon has obtained grade C
2 student Robert has obtained grade A
3 student Isabell has obtained grade B
4 student Adem has obtained grade F
5 student Harry has obtained grade A
No comments:
Post a Comment