Find the number of positive integers less than or equal to N that have an odd number of digits | C ++ implementation of the approach ; Function to return the number of positive integers less than or equal to N that have odd number of digits ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int odd_digits ( int n ) { if ( n < 10 ) return n ; else if ( n / 10 < 10 ) return 9 ; else if ( n / 100 < 10 ) return 9 + n - 99 ; else if ( n / 1000 < 10 ) return 9 + 900 ; else if ( n / 10000 < 10 ) return 909 + n - 9999 ; else return 90909 ; } int main ( ) { int n = 893 ; cout << odd_digits ( n ) ; return 0 ; }