Greetings, this is my first post here but I will try to do it correctly. I know this specific question is a common one, but I am not looking for someone to do it for me, I just need someone to help me out a little. I understand the basics of recursion, but I have run into something that has stumped me. The question is, using only one recursive function, produce the pattern below based on the integer n(maximum amount of asterisks being displayed. I can either make the top of the hill to appear or the bottom. I am having trouble making both the top and bottom appear with only one function recursively. I can do this without recursion but only with 2 separate functions.
so if n = 5 then the hill would look like this,
*
**
***
****
*****
****
***
**
*
My code for the function so far is,
void stars(int n){
if(n > 0){
stars(n-1);
for(int i = 0; i < n;i++){
cout << "*";
}
cout << endl;
// if I were to place stars(n-1) here I would get the bottom half
}
}
----------------------
output:
*
**
***
****
*****
----------------------
I am just having trouble wrapping my head around how to do all of this in 1 function recursively. If you can show me something that could help, please let me know. Thanks in advance!