In this program, we will calculate the product of digits of a number.
Steps to solve the program
- Take a number as input through the user.
- Create a variable product and assign its value equal to 1.
- Using a while loop find the sum of digits of a number.
- While the number is greater than 0 divide the number by 10 using % and store the remainder in a variable.
- Multiply the remainder by the product variable.
- Now divide the number by 10 using //.
- Print the final output.
num = int(input("Enter a number: "))
product = 1
while num > 0:
rem = num%10
product = product * rem
num = num // 10
print("Product of given number is: ",product)
Output :
Enter a number: 56
Product of given number is: 30