Write a C program to enter any number from user and calculate product of its digits. How to find product of digits of any number using loop in C programming. C program to find product of digits.

Input number: 1234

Output product of digits: 1 * 2 * 3 * 4 = 24

Happy coding ;)

**Example:**Input number: 1234

Output product of digits: 1 * 2 * 3 * 4 = 24

### Required knowledge

Basic C programming, Loop### Logic to find product of digits

Before moving on to the logic of finding product of digits one thing you must be done with is how to find the last digit of any number. Now, moving on to logic of this program can be divided in three basic steps:- Find the last digit of number by performing modular division.
- Multiply the last digit just found above to product.
- Remove the last digit from number by dividing the number by 10.

### Program to find product of digits

/** * C program to calculate product of digits of any number */ #include <stdio.h> int main() { int n; long product=1; /* Reads a number from user */ printf("Enter any number to calculate product of digit: "); scanf("%d", &n); /* Repeat the steps till n becomes 0 */ while(n!=0) { /* Gets the last digit from n and multiplies to product */ product = product * (n % 10); /* Removes the last digit from n */ n = n / 10; } printf("\nProduct of digits = %ld", product); return 0; }

**Note:**Initializing product=1 is must if you haven't initialized it before calculating product then you will get garbage value.

Output

Enter any number to calculate product of digit: 1234

Product of digits = 24

Product of digits = 24

Happy coding ;)

### You may also like

- Loop programming exercises index.
- C program to calculate sum of digits.
- C program to print sum of all even numbers between 1 to n.
- C program to print sum of all odd numbers between 1 to n.
- C program to print sum of all prime numbers between 1 to n.
- C program to enter any number and print its table.
- C program to enter any number and check whether it is palindrome or not.
- C program to enter any number and calculate its factorial.
- C program to print all prime numbers between 1 to n.
- C program to print all Armstrong numbers between 1 to n.
- C program to print all Perfect numbers between 1 to n.
- C program to print all Strong numbers between 1 to n.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).