Write a C++ program to calculate product of digits of a number.
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;
}
Comments
Leave a comment