Write a function in C++ to calculate product of digits of any number
#include <iostream>
using namespace std;
int digitProduct(int n)
{
int prod = 1;
while (n != 0) {
prod = prod * (n % 10);
n = n / 10;
}
return prod;
}
int main()
{
int n = 468;
cout << digitProduct(n) << '\n';
return 0;
}
Output:
192
Comments
Leave a comment