Write An Algorithm
Write An Algorithm
Write An Algorithm
multiplies them
together and print out their product.
Pseudo code:
Input 2 numbers
Find the product by multiplying them
Print their product
Algorithm:
Input num1
Input num2
Product = num1*num2
print Product
Write an algorithm and pseudo code that tells a user that the
number they entered
is not a 5 or a 6
Pseudo code:
Input a number
If number not equal to 5 and not equal to 6
Then print “The number entered is neither ‘5’ nor ‘6’ ”
Algorithm:
Input num
If (num≠5 and ≠6)
Print “The number entered is neither ‘5’nor ‘6’”
Endif
5. Two friends decide who gets the last slice of a cake by flipping a
coin five times.
The first person to win three flips wins the cake. An input of 1
means player 1 wins
a flip, and a 2 means player 2 wins a flip. Design an algorithm to
determine who
takes the cake?
SET i := 1, player1 := 0, player2 := 0
WHILE i <= 5 DO
INPUT coin
IF coin = 1 THEN
player1 := player1 + 1
ELSE
player2 := player2 + 1
END IF
IF player1 = 3 THEN
PRINT ‘Player 1 won the last slice.’
BREAK
END IF
IF player2 = 3 THEN
PRINT ‘Player 2 won the last slice.’
BREAK
END IF
INCREASE i BY 1
END LOOP