CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;
void printmany(char c,int N,int i=1){
if(i<=N){
cout<<c;
if(c=='*'){cout<<' ';}
printmany(c,N,i+1);
}
}
void diamond(int max, int begin=1){
printmany(' ',max-begin);
printmany('*',begin);
cout<<'\n';
if(begin<max){
diamond(max,begin+1);
printmany(' ',max-begin);
printmany('*',begin);
cout<<'\n';
}
}
int main() {
int a=3;
cin>>a;
diamond(a);
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run