C Online Compiler
Example: Student Grading System with Nested If-Else in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Student Grading System with Nested If-Else #include <stdio.h> int main() { int score; // Step 1: Prompt user for input printf("Enter student's score (0-100): "); // Step 2: Read the score from user scanf("%d", &score); // Step 3: Outer if-else for score validation if (score >= 0 && score <= 100) { // Step 4: Inner if-else if ladder for grade assignment if (score >= 90) { printf("Grade: A\n"); } else if (score >= 80) { printf("Grade: B\n"); } else if (score >= 70) { printf("Grade: C\n"); } else if (score >= 60) { printf("Grade: D\n"); } else { printf("Grade: F\n"); } } else { // Step 5: Handle invalid score printf("Invalid score entered. Score must be between 0 and 100.\n"); } return 0; }
Output
Clear
ADVERTISEMENTS