Print a box shaped with recursion?

Oct 6, 2014 at 1:20pm
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 Oct 6, 2014 at 1:23pm
Oct 6, 2014 at 1:45pm
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.
Oct 6, 2014 at 1:52pm
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 Oct 6, 2014 at 1:53pm
Oct 6, 2014 at 2:40pm
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.