Skip to content

Commit 0806077

Browse files
authored
Diamond of Stars
This is one of the questions of Pattern in C++ which gives more insights into how Loops work and how the Iteration takes place in nested Loops.
1 parent e7e85f8 commit 0806077

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

cpp/Diamond of Stars.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main() {
6+
7+
int n,k,i,j;
8+
cin >> n;
9+
for(i = 1; i<=(n+1)/2;i++){
10+
for(j = 1; j<=((n+1)/2)-i;j++)
11+
cout << ' ';
12+
for(k = 1; k<=2*i-1;k++)
13+
cout << '*';
14+
cout << endl;
15+
}
16+
for(i = (n-1)/2; i>=1;i--){
17+
for(j = 1; j<=((n-1)/2)-i+1;j++)
18+
cout << ' ';
19+
for(k = 1; k<=2*i-1;k++)
20+
cout << '*';
21+
cout << endl;
22+
}
23+
24+
}

0 commit comments

Comments
 (0)