Number of digits in the product of two numbers | C ++ implementation to count number of digits in the product of two numbers ; function to count number of digits in the product of two numbers ; absolute value of the product of two numbers ; if product is 0 ; count number of digits in the product ' p ' ; required count of digits ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countDigits ( int a , int b ) { int count = 0 ; int p = abs ( a * b ) ; if ( p == 0 ) return 1 ; while ( p > 0 ) { count ++ ; p = p / 10 ; } return count ; } int main ( ) { int a = 33 ; int b = -24 ; cout << " Number ▁ of ▁ digits ▁ = ▁ " << countDigits ( a , b ) ; return 0 ; }