-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdiamond.cpp
More file actions
62 lines (52 loc) · 713 Bytes
/
diamond.cpp
File metadata and controls
62 lines (52 loc) · 713 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<iostream>
using namespace std;
void diamond(int index, int odd_number);
int main()
{
int odd_number;
cin>>odd_number;
diamond(1,odd_number);
cout<<endl;
return 0;
}
void diamond(int index, int odd_number)
{
if(index>odd_number)
return;
for(int i=1;i<=(odd_number-index)/2;i++)
cout<<" ";
for(int i=1;i<=index;i++)
cout<<"*";
cout<<endl;
diamond(index+2,odd_number);
if(index!=odd_number)
{
for(int i=1;i<=(odd_number-index)/2;i++)
cout<<" ";
for(int i=1;i<=index;i++)
cout<<"*";
cout<<endl;
}
}
/*
Test case 1:
5
*
***
*****
***
*
Test case 2:
11
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
*/