RECURSION-LEXICOGRAPHICAL ORDER one test case not running

link to ques-https://hack.codingblocks.com/contests/c/457/360

#include
#include

using namespace std;

void Print(int n)
{ cout<<0<<" ";
for(int i = 1; i <= 9; i ++){
int j = 1;
while( j <= n){
for(int m = 0; m < j ; ++ m){
if(m + j * i <= n){
cout << m + j * i << " ";
}
}
j *= 10;
}
}
}

int main()
{
int n;
cin>>n;
Print(n);
return 0;
}

Hey You need to write the recursive code for this.
Think recursively.Here is my code for reference -
https://ide.codingblocks.com/#/s/16028

sir i am not getting the logic behind this code…could you please help

Think like after printing 0 we need to print 1 and all numbers starting with one.
Then 2 and all numbers starting with 2 and so on.
So we can do this in a for loop for digits 1 to 9.We can call a print function and pass it 1 or 2 or 3 till 9.
In Print Function : print 1 and before calling print for 2,we will call print for 10*1.
Next number is 10 and then 11,12,13…19.We can print this using a for loop
But lexicographicaly 100 comes first.So 10 will call this print function again but this time multplied by 10 so that 100 and its series can be printed

there is also a simple way iterate to number then covert it to string using stringstream class the store all and sort them it will automatically sorted in an lexographical order
or u can use set to store then it is automatically lexo sorted

#include <bits/stdc++.h>
using namespace std;

void print_lexiographicall(int n, int a)
{
    // cout << 0 << " ";
    if(a > n)
        return;
    cout << a << " ";
    int i =0;
    if (a==0)
        i = 1;
    for(; i<=9; i++)
        print_lexiographicall(n, a*10 + i);
}






int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    print_lexiographicall(n, 0);
    
}