Write a recursive function to generate a pattern of stars, such as the following: * * * * * * * * * * * * * * * * * * * *
#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;
}
Comments
Leave a comment