Write an algorithm that performs the following: Ask a user to enter a number. If the number is between 5 and 15, write the word GREEN. If the number is between 15 and 25, write the word BLUE. If the number is between 25 and 35, write the word ORANGE. If it is any other number, write that ALL COLOURS ARE BEAUTIFUL.
Question
Write an algorithm that performs the following: Ask a user to enter a number. If the number is between 5 and 15, write the word GREEN. If the number is between 15 and 25, write the word BLUE. if the number is between 25 and 35 , write the word ORANGE. If it is any other number, write that ALL COLOURS ARE BEAUTIFUL.
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
Here is the algorithm to achieve the mentioned task:
Input: A number from the user
Process: Check which range the number falls into and determine the appropriate output
Output: Depending on the range, output the corresponding word or phrase
Pseudocode
PRINT "Enter a number"
INPUT number
IF 5 <= number < 15 THEN
PRINT "GREEN"
ELSE IF 15 <= number < 25 THEN
PRINT "BLUE"
ELSE IF 25 <= number < 35 THEN
PRINT "ORANGE"
ELSE
PRINT "ALL COLOURS ARE BEAUTIFUL"
Explanation
Ask the user to enter a number: Start by prompting the user to enter a number.
Check the range of the number:
If the number is between 5 and 15 (inclusive of 5 and less than 15), print "GREEN".
If the number is between 15 and 25 (inclusive of 15 and less than 25), print "BLUE".
If the number is between 25 and 35 (inclusive of 25 and less than 35), print "ORANGE".
If the number does not fall into any of these ranges, print "ALL COLOURS ARE BEAUTIFUL".
Each step ensures that the correct message is printed based on the range in which the entered number falls.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month