Calculate the product of digits of a number

In this program, we will calculate the product of digits of a number.

Steps to solve the program
  1. Take a number as input through the user.
  2. Create a variable product and assign its value equal to 1.
  3. Using a while loop find the sum of digits of a number.
  4. While the number is greater than 0 divide the number by 10 using % and store the remainder in a variable.
  5. Multiply the remainder by the product variable.
  6. Now divide the number by 10 using //.
  7. 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
				
			

calculate the sum of digits of a number

enter a number and print its reverse

Leave a Comment