In this article, we will learn, different star pattern programs in C++
Star Series and Patterns Programs in C++
Half, Full, Incremented and Decrement Stars Series, Pyramid Pattern programs
Example 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> using namespace std; int main() { int i, j; int MAX = 10; for (i = 0; i < MAX; i++) { for (j = 0; j <= i; j++) { cout<<"*"; } cout<<endl; } } |
Output:
Example 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> using namespace std; int main() { int i, j; int MAX = 10; for (i = MAX; i >= 0; i--) { for (j = 0; j <= i; j++) { cout<<"*"; } cout<<endl; } } |
Output:
Example 3:
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; int main() { int i, j; int space = 10; int MAX = space; for (i = 0; i < MAX; i++) { for (j = 0; j < space; j++) { cout<<" "; } for (j = 0; j <= i; j++) { cout<<"* "; } cout<<"\n"; space--; } } |
Output:
Example 4:
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 |
#include <iostream> using namespace std; int main() { int i, j; int space = 10; int MAX = space+1; for (i = 0; i < MAX; i++) { for (j = 0; j < space; j++) { cout<<" "; } for (j = 0; j <= i; j++) { cout<<"* "; } cout<<"\n"; space--; } space = 0; for (i = MAX; i > 0; i--) { for (j = 0; j < space; j++) { cout<<" "; } for (j = 0; j < i; j++) { cout<<"* "; } cout<<"\n"; space++; } } |
Output:
Example 5:
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 |
#include <iostream> using namespace std; int main() { int i, j; int space = 0; int MAX = 10; for (i = MAX; i > 0; i--) { for (j = 0; j < i; j++) { cout<<"*"; } for (j = 0; j < space; j++) { cout<<" "; } for (j = 0; j < i; j++) { cout<<"*"; } cout<<"\n"; space += 2; } } |
Output:
Example 6:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> using namespace std; int main() { int i, j; for (i = 1; i <= 10; i++) { for (j = 1; j <= 20; j++) { cout<<"*"; } cout<<endl; } } |
Output:
Example 7:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> using namespace std; int main() { int i, j; int MAX = 10; for (i = 1; i <= MAX; i++) { for (j = 1; j <= i; j++) { if (j == 1 || j == i || i == MAX) { cout<<"*"; } else { cout<<" "; } } cout<<endl; } } |
Output:
Example 8:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> using namespace std; int main() { int i, j, k, l = 1; int space = 5; int MAX = space; for (i = 1; i <= MAX; i++) { for (j = space; j >= i; j--) { cout<<" "; } for (k = 1; k <= l; k++) { cout<<k; } l = l + 2; cout<<"\n"; } } |
Output:
Example 9:
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 |
#include <iostream> using namespace std; int main() { int i, j; int MAX = 10; for (i = 1; i <= MAX; i++) { for (j = i; j < MAX; j++) { cout<<" "; } for (j = 1; j <= (2 * i - 1); j++) { if (i == MAX || j == 1 || j == (2 * i - 1)) { cout<<"*"; } else { cout<<" "; } } cout<<endl; } } |
Output: