#include <stdio.h>
// Function prototype
char getGrade(int score);
// Function definition
/**
* Function Name: getGrade
*
* Function Block:
* Determines the letter grade based on the given score.
*
* @param score The test score (0-100).
* @return The letter grade corresponding to the score, or 'I' for invalid scores.
*/
char getGrade(int score) {
if (score < 0 || score > 100) {
return 'I'; // Invalid score
} else if (score >= 90) {
return 'A';
} else if (score >= 80) {
return 'B';
} else if (score >= 70) {
return 'C';
} else if (score >= 60) {
return 'D';
} else {
return 'F';
}
}
int main() {
int score;
// Test cases
score = 95;
printf("Score: %d, Grade: %c\n", score
, getGrade
(score
)); // Expected output: A
score = 85;
printf("Score: %d, Grade: %c\n", score
, getGrade
(score
)); // Expected output: B
score = 75;
printf("Score: %d, Grade: %c\n", score
, getGrade
(score
)); // Expected output: C
score = 65;
printf("Score: %d, Grade: %c\n", score
, getGrade
(score
)); // Expected output: D
score = 55;
printf("Score: %d, Grade: %c\n", score
, getGrade
(score
)); // Expected output: F
score = -5;
printf("Score: %d, Grade: %c\n", score
, getGrade
(score
)); // Expected output: I
score = 105;
printf("Score: %d, Grade: %c\n", score
, getGrade
(score
)); // Expected output: I
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBGdW5jdGlvbiBwcm90b3R5cGUKY2hhciBnZXRHcmFkZShpbnQgc2NvcmUpOwoKLy8gRnVuY3Rpb24gZGVmaW5pdGlvbgovKioKICogRnVuY3Rpb24gTmFtZTogZ2V0R3JhZGUKICogCiAqIEZ1bmN0aW9uIEJsb2NrOgogKiBEZXRlcm1pbmVzIHRoZSBsZXR0ZXIgZ3JhZGUgYmFzZWQgb24gdGhlIGdpdmVuIHNjb3JlLgogKiAKICogQHBhcmFtIHNjb3JlIFRoZSB0ZXN0IHNjb3JlICgwLTEwMCkuCiAqIEByZXR1cm4gVGhlIGxldHRlciBncmFkZSBjb3JyZXNwb25kaW5nIHRvIHRoZSBzY29yZSwgb3IgJ0knIGZvciBpbnZhbGlkIHNjb3Jlcy4KICovCmNoYXIgZ2V0R3JhZ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