Q1: Write an algorithm to input a number. Find
its square if the entered number is multiple of
10. If entered number if not a multiple of 10,
then find its cube. [5]
Answers
Answered by
2
We'll call the input number .
If then
return
else
return
If you've not yet learned about modular arithmetic, then you can equivalently
just check if the last digit of the entered number is a 0 or not.
If it is 0 then the number is a multiple of 10. If it does not end in 0, then it is not a multiple of 10.
In e.g. python you could implement this as
def algorithm
if n % 10 == 0:
n = n ** 2
else:
n = n ** 3
return n
Similar questions
History,
4 months ago
Social Sciences,
4 months ago
Math,
4 months ago
Math,
8 months ago
Physics,
8 months ago