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 ; if either of the number is 0 , then product will be 0 ; required count of digits ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countDigits ( int a , int b ) { if ( a == 0 b == 0 ) return 1 ; return floor ( log10 ( abs ( a ) ) + log10 ( abs ( b ) ) ) + 1 ; } int main ( ) { int a = 33 ; int b = -24 ; cout << countDigits ( a , b ) ; return 0 ; }