Answer to Question #328643 in C++ for Nickname

Question #328643

Write a C++ program to calculate product of digits of a number.

1
Expert's answer
2022-04-14T06:16:35-0400
using namespace std;
int product(int number){
    int prod = 1, i;
    for(i=number; i>0; i=i/10)     {
        prod = prod*(i % 10);
    }
    return prod;
}
int main(){
    int n;
    cout<<"Enter int N:  ";
    cin>>n;
    cout<<product(n)<<endl;

}




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