C Programming

Exercise Question

Objective:

Enter 3 subject marks of a student, calculate the percentage, and find the grade as per the following rules. It is assumed that the maximum marks of each subject are 100.

1. If percentage >= 85, then the grade will be S
2. If the percentage is between 75-84.99, then the grade will be A
3. If the percentage is between 65-74.99, then the grade will be B
4. If the percentage is between 55-64.99, then the grade will be C
5. If the percentage is between 50-54.99, then the grade will be D
6. If the percentage is <50, then the grade will be F

Program / Solution:

```#includestdio.h
int main() {
int m1,m2,m3;
float per;
char gd;

printf("Enter 3 subject marks: ");
scanf("%d %d %d",&m1,&m2,&m3);

per = (m1 + m2 + m3)/3.0f;

if(per >= 85) {
gd = 'S';
} else if(per >= 75) {
gd = 'A';
} else if(per >= 65) {
gd = 'B';
} else if(per >= 55) {
gd = 'C';
} else if(per >= 50) {
gd = 'D';
} else {
gd = 'F';
}

return 0;

}
```

Sample Output:

```Enter 3 subject marks: 85 74 68
Percentage = 75.67
```