Answer to Question #247118 in C++ for ghhuh

Question #247118

Write a function in C++ to calculate product of digits of any number


1
Expert's answer
2021-10-05T18:17:17-0400
#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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS