Programs to find the letter grade of a student are shown here. The letter grade is calculated according to the score obtained by the students. The following table depicts the grade table and the ranges of the score.

Outstanding 90 to 100 O
Excellent 80 to below 90 E
Very good 70 to below 80 A
Good 60 to below 70 B
Fair 50 to below 60 C
Below average 40 to below 50 D
Failed Below 40 F

For example, if the score is 65, then according to the table, the grade is B, and if the score is 93, then it is O.

## 1. Algorithm to Find the Letter Grade of a Student

1. Take the score as input.

2. If the score is greater than 100 or less than 0, display the score as invalid.

3. If the score is between 90 and 100, display letter grade O as the output.

4. If the score is between 80 and below 90, display letter grade E as the output.

5. If the score is between 70 and below 80, display letter grade A as the output.

6. If the score is between 60 and below 70, display letter grade B as the output.

7. If the score is between 50 and below 60, display letter grade C as the output.

8. If the score is between 40 and below 50, display letter grade D as the output.

9. If the score is below 40, display letter grade F as the output.

## 2. Pseudocode to Find the Letter Grade of a Student

Input : Student score $s$

Output : Letter grade of the score $s$

1. Procedure letterGrade($s$):

2. If $s > 100$ or $s < 0$:

3. Return "Invalid score!"

4. Else If $s >= 90$:

5. Return "O"

6. Else If $s >= 80$:

7. Return "E"

8. Else If $s >= 70$:

9. Return "A"

10. Else If $s >= 60$:

11. Return "B"

12. Else If $s >= 50$:

13. Return "C"

14. Else If $s >= 40$:

15. Return "D"

16. Else:

17. Return "F"

18. End Procedure

## 3. Time complexity to Find the Letter Grade of a Student

Time Complexity: O(1)

## 4. Program to Find the Letter Grade of a Student

In this section, the C, C++, Java, Python and C# programs to find the letter grade w.r.t score are given. A valid range of score is 0 to 100.

## 4.1. C Program to Find the Letter Grade of a Student

Code has been copied
/**********************************************
alphabetacoder.com
C program to find the letter grade of a student
***********************************************/
#include <stdio.h>

int main() {
// declare variables
double score;

// take input
printf("Enter the score: ");
scanf("%lf", & score);

if (score > 100 || score < 0)
printf("Invalid score!");
else if (score >= 90)
else if (score >= 80)
else if (score >= 70)
else if (score >= 60)
else if (score >= 50)
else if (score >= 40)
else

return 0;
}


Output

#### Case 1:

Enter the score: 92

#### Case 2:

Enter the score: 65.5

#### Case 3:

Enter the score: 73

## 4.2. C++ Program to Find the Letter Grade of a Student

Code has been copied
/************************************************
alphabetacoder.com
C++ program to find the letter grade of a student
*************************************************/

#include <iostream>

using namespace std;

int main() {
// declare variables
double score;

// take input
cout << "Enter the score: ";
cin >> score;

if (score > 100 || score < 0)
cout << "Invalid score!";
else if (score >= 90)
else if (score >= 80)
else if (score >= 70)
else if (score >= 60)
else if (score >= 50)
else if (score >= 40)
else

return 0;
}


Output

#### Case 1:

Enter the score: 38

#### Case 2:

Enter the score: 56.75

#### Case 3:

Enter the score: 49

## 4.3. Java Program to Find the Letter Grade of a Student

Code has been copied
/*************************************************
alphabetacoder.com
Java program to find the letter grade of a student
**************************************************/

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// declare variables
double score;

// declare instance of Scanner class
Scanner sc = new Scanner(System.in);

// take input
System.out.print("Enter the score: ");
score = sc.nextDouble();

if (score > 100 || score < 0)
System.out.print("Invalid score!");
else if (score >= 90)
else if (score >= 80)
else if (score >= 70)
else if (score >= 60)
else if (score >= 50)
else if (score >= 40)
else
}
}


Output

#### Case 1:

Enter the score: 38

#### Case 2:

Enter the score: 56.75

#### Case 3:

Enter the score: 49

## 4.4. Python Program to Find the Letter Grade of a Student

Code has been copied
# ****************************************************
#               alphabetacoder.com
# Python program to find the letter grade of a student
# ****************************************************

# take input
score = float(input("Enter the score: "))

if score > 100 or score < 0:
print("Invalid score!")
elif score >= 90:
elif score >= 80:
elif score >= 70:
elif score >= 60:
elif score >= 50:
elif score >= 40:
else:


Output

#### Case 1:

Enter the score: 105

Invalid score!

#### Case 2:

Enter the score: 47.5

#### Case 3:

Enter the score: 62

## 4.5. C# Program to Find the Letter Grade of a Student

Code has been copied
/*************************************************
alphabetacoder.com
C# program to find the letter grade of a student
**************************************************/

using System;

class Program {
static void Main(string[] args) {
// declare variables
double score;

// take input
Console.Write("Enter the score: ");

if(score > 100 || score < 0)
Console.WriteLine("Invalid score!");
else if (score >= 90)
else if (score >= 80)
else if (score >= 70)
else if (score >= 60)
else if (score >= 50)
else if (score >= 40)
else

// wait for user to press any key
}
}
}


Output

#### Case 1:

Enter the score: -5

Invalid score!

#### Case 2:

Enter the score: 39