Product of Digits in a Number using Dart
In the following program, we read a number from user via console, and find the products of digits in this number.
We use for loop to iterate over the digits of the number, and accumulate the product of the digits in result.
Refer Dart For Loop tutorial.
main.dart
</>
Copy
import 'dart:io';
void main() {
print('Enter N');
int N = int.parse(stdin.readLineSync()!);
int result = 1;
for (int i = N; i > 0; i = (i / 10).floor()) {
result *= (i % 10);
}
print('Product of digits\n$result');
}
Output
Enter N
12345
Product of digits
120
Summary
In this Dart Tutorial, we have written a Dart program to find the product of digits in given number.