Cumulative product of digits of all numbers in the given range | C ++ program to print the product of all numbers in range L and R ; Function to get product of digits ; Function to find the product of digits of all natural numbers in range L to R ; Iterate between L to R ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getProduct ( int n ) { int product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = n / 10 ; } return product ; } int productinRange ( int l , int r ) { if ( r - l > 9 ) return 0 ; else { int p = 1 ; for ( int i = l ; i <= r ; i ++ ) p *= getProduct ( i ) ; return p ; } } int main ( ) { int l = 11 , r = 15 ; cout << productinRange ( l , r ) << endl ; l = 1 , r = 15 ; cout << productinRange ( l , r ) ; return 0 ; }