Question #265549

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: * * * * * * * * * * * * * * * * * * * *


Expert's answer

#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;
}


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!

LATEST TUTORIALS
APPROVED BY CLIENTS