C++ Saved Program: majestic-home



Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <iostream>

char* allocate(char* a, int n)
{
  if(n == 0)
    {
      *a = '\0';
      return a;
    }
  else
    *a = 'x';
  return allocate(a+1, n-1);
}

char* print(int n)
{
  int const size = n+1;
  char a[size];

  if(n == 0)
    {
      *a = '\0';
      return a;
    }
  else
    *a = 'x';
  return ( allocate(a+1,n-1) )-n;
 
}

int main(void)
{
  int i = 10;
   while(i != 0)
    {
      std::cout << print(i--)<< std::endl;
    }
  return 0;
}
Execute