# Program to calculate product of digits of a number

Given a number, the task is to find the product of the digits of a number.

Examples:

```Input: n = 4513
Output: 60

Input: n = 5249
Output: 360
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

General Algorithm for product of digits in a given number:

1. Get the number
2. Declare a variable to store the product and set it to 1
3. Repeat the next two steps till the number is not 0
4. Get the rightmost digit of the number with help of remainder ‘%’ operator by dividing it with 10 and multiply it with product.
5. Divide the number by 10 with help of ‘/’ operator
6. Print or return the product

Below is the solution to get the product of the digits:

## C++

 `// cpp program to compute ` `// product of digits in the number. ` `#include ` `using` `namespace` `std; ` ` `  `/* Function to get product of digits */` `int` `getProduct(``int` `n) ` `{ ` `    ``int` `product = 1; ` ` `  `    ``while` `(n != 0)  ` `    ``{ ` `        ``product = product * (n % 10); ` `        ``n = n / 10; ` `    ``} ` ` `  `    ``return` `product; ` `} ` ` `  `// Driver program ` `int` `main() ` `{ ` `    ``int` `n = 4513; ` `    ``cout << (getProduct(n)); ` `} ` ` `  `// This code is contributed by ` `// Surendra_Gangwar `

## Java

 `// Java program to compute ` `// product of digits in the number. ` ` `  `import` `java.io.*; ` ` `  `class` `GFG { ` ` `  `    ``/* Function to get product of digits */` `    ``static` `int` `getProduct(``int` `n) ` `    ``{ ` `        ``int` `product = ``1``; ` ` `  `        ``while` `(n != ``0``) { ` `            ``product = product * (n % ``10``); ` `            ``n = n / ``10``; ` `        ``} ` ` `  `        ``return` `product; ` `    ``} ` ` `  `    ``// Driver program ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` `        ``int` `n = ``4513``; ` ` `  `        ``System.out.println(getProduct(n)); ` `    ``} ` `} `

## Python3

 `# Python3 program to compute ` `# product of digits in the number. ` ` `  `# Function to get product of digits  ` `def` `getProduct(n): ` ` `  `    ``product ``=` `1` ` `  `    ``while` `(n !``=` `0``): ` `        ``product ``=` `product ``*` `(n ``%` `10``) ` `        ``n ``=` `n ``/``/` `10` ` `  `    ``return` `product ` ` `  `# Driver Code ` `n ``=` `4513` `print``(getProduct(n)) ` ` `  `# This code is contributed ` `# by mohit kumar `

## C#

 `// C# program to compute  ` `// product of digits in the number.  ` `using` `System; ` ` `  `class` `GFG  ` `{  ` ` `  `    ``/* Function to get product of digits */` `    ``static` `int` `getProduct(``int` `n)  ` `    ``{  ` `        ``int` `product = 1;  ` ` `  `        ``while` `(n != 0)  ` `        ``{  ` `            ``product = product * (n % 10);  ` `            ``n = n / 10;  ` `        ``}  ` ` `  `        ``return` `product;  ` `    ``}  ` ` `  `    ``// Driver program  ` `    ``public` `static` `void` `Main()  ` `    ``{  ` `        ``int` `n = 4513;  ` ` `  `        ``Console.WriteLine(getProduct(n));  ` `    ``}  ` `} ` ` `  `// This code is contributed by Ryuga `

## PHP

 ` `

Output:

```60
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.