luc043.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 12 Dec 2025
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Write a program to find the grace marks for a student using switch. The user should enter the class obtained by the student and the number of subjects he has failed in. Use the following logic. - If the student gets first class and he fails in more than 3 subjects, he does not get any grace, Otherwise, he gets a grace of 5 marks per subject. - If the student gets second class and he fails in more than 2 subjects, he does not get any grace. Otherwise, he gets a grace of 4 marks per subject. - If the student gets third class and he fails in more than 1 subject, then he does not get any grace. Otherwise, he gets a grace of 5 marks.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
#include <stdio.h>
int main()
{
int studentClass, failedSubjectCount, graceMarks = 0;
printf("Class obtained by the student (Enter 1 for First Class, 2 for Second Class, 3 for Third Class): ");
scanf("%d", &studentClass);
printf("Failed Subject Count: ");
scanf("%d", &failedSubjectCount);
if (failedSubjectCount < 0) {
printf("\nFailed subject count cannot be negative.");
return 1;
}
switch (studentClass)
{
case 1:
if (failedSubjectCount <= 3)
{
graceMarks += 5 * failedSubjectCount;
}
break;
case 2:
if (failedSubjectCount <= 2)
{
graceMarks += 4 * failedSubjectCount;
}
break;
case 3:
if (failedSubjectCount <= 1)
{
graceMarks += 5 * failedSubjectCount;
}
break;
default:
printf("\nWrong Choice.");
return 1;
}
printf("\nStudent will get %d grace marks.", graceMarks);
return 0;
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46