Answer to Question #265550 in C++ for Usama

Question #265550

Write a recursive function to generate a pattern of stars, such as the following: * * * * * * * * * * * * * * * * * * * *


1
Expert's answer
2021-11-19T17:16:42-0500
#include <iostream>
using namespace std;
void pattern(int n){
    if(n == 0) return;
    for(int i = 0; i < n; i++){
        cout<<"*";
    }
    cout<<endl;
    pattern(n - 1);
}
int main(){
    pattern(6);
    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