Computer Science

Write an algorithm that accepts four numbers as input and find the largest and smallest of them.

Algo & Flowcharts

2 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