Print a box shaped with recursion?

I want to make a program that print a box shaped like this if i input 4


****
*  *
*  *
****


i know how to do it with for loops but not with recursion
Last edited on
How about writitng one line:
1
2
3
4
5
6
7
8
9
void foo( int size, int pos, char fill ) {
  if ( pos < size ) {
    std::cout << fill;
    foo( size, ++pos, fill );
  }
  else {
    std::cout << "*\n";
  }
}

No, it is not perfect. It could do the first and last line (if called correctly), but it does need tinkering for the others.
closed account (28poGNh0)
@keskiverto

I test your code and I think it does not working
also do we really need a recursion here?
Last edited on
It is not supposed to "work". Mere food for thought.

There is no "need" in an attempt to explore and learn.
Topic archived. No new replies allowed.