-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproductofdigits.cpp
More file actions
22 lines (17 loc) · 1007 Bytes
/
productofdigits.cpp
File metadata and controls
22 lines (17 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Calculate the product of digits of a number using a while loop.
#include <iostream>
using namespace std;
int main() {
long long number; // Use long long to handle large numbers
cout << "Enter a number: ";
cin >> number;
long long product = 1;
// Calculate the product of digits
while (number != 0) {
int digit = number % 10; // Extract the last digit
product *= digit; // Multiply with the product
number /= 10; // Remove the last digit
}
cout << "Product of digits: " << product << endl;
return 0;
}