Answer to Question #265549 in C++ for Usama

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


1
Expert's answer
2021-11-20T06:43:05-0500
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS