Ternary Nesting
C
Medium
5 views
Problem Description
By assigning grade with nested ternary operators (90+=A, 80+=B, etc). Then write the same logic if-else. Readability compare.
Official Solution
#include <stdio.h>
int main() {
int marks;
char grade;
printf("Enter marks: ");
scanf("%d", &marks);
if (marks >= 90)
grade = 'A';
else if (marks >= 80)
grade = 'B';
else if (marks >= 70)
grade = 'C';
else if (marks >= 60)
grade = 'D';
else
grade = 'F';
printf("Grade = %cn", grade);
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!