Created
January 4, 2025 02:12
-
-
Save lakshyaraj2006/12c1ed38dc43bfa5302e249e8698110c to your computer and use it in GitHub Desktop.
A start pattern using c++ language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| void pattern1(int n) | |
| { | |
| int space = 0; | |
| for (int i = n; i >= 1; i--) | |
| { | |
| // stars | |
| for (int j = 1; j <= i; j++) | |
| { | |
| cout << "*"; | |
| } | |
| // space | |
| for (int j = 0; j < space; j++) | |
| { | |
| cout << " "; | |
| } | |
| // stars | |
| for (int j = i; j >= 1; j--) | |
| { | |
| cout << "*"; | |
| } | |
| cout << endl; | |
| space += 2; | |
| } | |
| } | |
| void pattern2(int n) | |
| { | |
| int space = 2 * (n - 1); | |
| for (int i = 1; i <= n; i++) | |
| { | |
| // stars | |
| for (int j = 1; j <= i; j++) | |
| { | |
| cout << "*"; | |
| } | |
| // space | |
| for (int j = 0; j < space; j++) | |
| { | |
| cout << " "; | |
| } | |
| // stars | |
| for (int j = i; j >= 1; j--) | |
| { | |
| cout << "*"; | |
| } | |
| cout << endl; | |
| space -= 2; | |
| } | |
| } | |
| int main() | |
| { | |
| int n; | |
| cin >> n; | |
| pattern1(n); | |
| pattern2(n); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment