206k views
0 votes
(Multiply the digits in an integer) Write a program that reads an integer between 0 and 1000 and multiplies all the digits in the integer. For example, if an integer is 932 , the multiplication of all its digits is 54 . Hint: Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10

User Freitass
by
3.4k points

1 Answer

3 votes

Answer:

number = int(input("Enter a number: "))

product = 1

while number > 0:

digit = number % 10

number -= digit

number /= 10

product *= digit

print(int(product))

Step-by-step explanation:

*The code is in Python

Ask the user for an integer

Initialize the product variable that will hold the multiplication of the digits

Initialize a while loop that iterates until number is greater than 0

To find the digit of a number, use number modulo 10. Then subtract the result from the number and divide the new number by 10.

Multiply each digit and hold the value in the product

When the loop is done, print the product

User Spbfox
by
4.3k points