Find the number of integers from 1 to n which contains digits 0 ' s ▁ and ▁ 1' s only | C ++ program to find the number of integers from 1 to n which contains digits 0 ' s ▁ and ▁ 1' s only ; Function to find the number of integers from 1 to n which contains 0 ' s ▁ and ▁ 1' s only ; If number is greater than n ; otherwise add count this number and call two functions ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countNumbers ( int x , int n ) { if ( x > n ) return 0 ; return 1 + countNumbers ( x * 10 , n ) + countNumbers ( x * 10 + 1 , n ) ; } int main ( ) { int n = 120 ; cout << countNumbers ( 1 , n ) ; return 0 ; }