Computer Science
Write an algorithm that accepts four numbers as input and find the largest and smallest of them.
Algo & Flowcharts
4 Likes
Answer
Step 1: INPUT num1, num2, num3, num4
Step 2: SET largest = num1
Step 3: SET smallest = num1
Step 4: IF num2 > largest THEN
Step 5: SET largest = num2
ELSE IF num2 < smallest THEN
Step 6: SET smallest = num2
Step 7: IF num3 > largest THEN
Step 8: SET largest = num3
ELSE IF num3 < smallest THEN
Step 9: SET smallest = num3
Step 10: IF num4 > largest THEN
Step 11: SET largest = num4
ELSE IF num4 < smallest THEN
Step 12: SET smallest = num4
Step 13: PRINT "The largest number is: " + largest
Step 14: PRINT "The smallest number is: " + smallest
Answered By
3 Likes
Related Questions
Write an algorithm to find a factorial of an inputted number.
"Decomposition leads to simplicity." How?
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 COLORS ARE BEAUTIFUL.Write an algorithm to find the greatest among two different numbers entered by the user.