Write a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, then the pattern generated is: * * * * * * * * * * * * * * * * * * * *
#include <iostream>
using namespace std;
void printLn(int len) {
for (;len>0;--len) cout << "*";
cout << '\n';
}
void printPattern(int N) {
for (int i=N; i>=1; --i)
printLn(i);
for (int i=2; i<=N; ++i)
printLn(i);
}
int main()
{
printPattern(4);
return 0;
}
Comments
Leave a comment