luc043.c (1939B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 12 Dec 2025 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a program to find the grace marks for a student using switch. 9 The user should enter the class obtained by the student and the 10 number of subjects he has failed in. Use the following logic. 11 - If the student gets first class and he fails in more than 3 12 subjects, he does not get any grace, Otherwise, he gets a grace 13 of 5 marks per subject. 14 - If the student gets second class and he fails in more than 2 15 subjects, he does not get any grace. Otherwise, he gets a grace 16 of 4 marks per subject. 17 - If the student gets third class and he fails in more than 1 18 subject, then he does not get any grace. Otherwise, he gets a 19 grace of 5 marks. 20 */ 21 /* Let Us C, Chap- 7, Page - 125, Qn No.: C */ 22 23 #include <stdio.h> 24 25 int main() 26 { 27 int studentClass, failedSubjectCount, graceMarks = 0; 28 printf("Class obtained by the student (Enter 1 for First Class, 2 for Second Class, 3 for Third Class): "); 29 scanf("%d", &studentClass); 30 printf("Failed Subject Count: "); 31 scanf("%d", &failedSubjectCount); 32 33 if (failedSubjectCount < 0) { 34 printf("\nFailed subject count cannot be negative."); 35 return 1; 36 } 37 38 switch (studentClass) 39 { 40 case 1: 41 if (failedSubjectCount <= 3) 42 { 43 graceMarks += 5 * failedSubjectCount; 44 } 45 break; 46 47 case 2: 48 if (failedSubjectCount <= 2) 49 { 50 graceMarks += 4 * failedSubjectCount; 51 } 52 break; 53 54 case 3: 55 if (failedSubjectCount <= 1) 56 { 57 graceMarks += 5 * failedSubjectCount; 58 } 59 break; 60 61 default: 62 printf("\nWrong Choice."); 63 return 1; 64 } 65 66 printf("\nStudent will get %d grace marks.", graceMarks); 67 return 0; 68 }