The source code to find the division of students based on percentage using the ternary operator is given below. The given program is compiled and executed successfully.
# Ruby program to find the division of students
# based on percentage using ternary operator
print "Enter percentage: ";
per = gets.chomp.to_f;
msg=per>=60 ? "FIRST" : per>=45 ? "SECOND" : per>=33 ? "THIRD" : "FAILED";
print "Division is: ",msg;
Output:
Enter percentage: 72.4
Division is: FIRST
Explanation:
In the above program, we read the percentage of the student from the user and found the division of students, and printed the appropriate message.
Program/Source Code:
The source code to find the division of students based on percentage using the ternary operator is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we read the percentage of the student from the user and found the division of students, and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer