Check if two numbers have same number of digits | C ++ implementation of the approach ; Function that return true if A and B have same number of digits ; Both must be 0 now if they had same lengths ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool sameLength ( int A , int B ) { while ( A > 0 && B > 0 ) { A = A / 10 ; B = B / 10 ; } if ( A == 0 && B == 0 ) return true ; return false ; } int main ( ) { int A = 21 , B = 1 ; if ( sameLength ( A , B ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }