Answer to Question #55036 in C++ for paul

Question #55036
write recursive functions to generate the following patterns of stars:
****
***
**
*
*
**
***
****
1
Expert's answer
2015-09-29T05:21:44-0400
Answer:
#include <iostream>

using namespace std;

void print_stars(int level)
{
for (int i = 0; i < level; ++i)
{
cout << '*';
}

cout << endl;
}

void print_stars_recursive(int level)
{
if (level < 1)
return;

print_stars(level);

print_stars_recursive(level - 1);

print_stars(level);
}

int main()
{
print_stars_recursive(4);

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS