C Program to find the product of digits of a number

The following is a C program to find the product of digits of a number:

Expected Output:

1st run:

2nd run:

How it works

The following table demonstrates what happens at each iteration of the while loop, assuming num = 234.

Iteration rem prod  num
After 1st iteration rem=234%10=4   prod=1*4=4 num=234/10=23
After 2nd iteration rem=23%10=3   prod=4*3=12 num=23/10=2
After 3rd iteration rem=2%10=2   prod=12*2=24 num=2/10=0

Recommended Reading:

Leave a Comment

%d bloggers like this: