Find n | C ++ program to find n - th number containing only 4 and 7. ; If n is odd , append 4 and move to parent ; If n is even , append 7 and move to parent ; Reverse res and return . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string findNthNo ( int n ) { string res = " " ; while ( n >= 1 ) { if ( n & 1 ) { res = res + "4" ; n = ( n - 1 ) / 2 ; } else { res = res + "7" ; n = ( n - 2 ) / 2 ; } } reverse ( res . begin ( ) , res . end ( ) ) ; return res ; } int main ( ) { int n = 13 ; cout << findNthNo ( n ) ; return 0 ; }