Last active
November 30, 2024 02:41
-
-
Save dgodfrey206/b0bacc9be9b7a289803ab94893fa0e26 to your computer and use it in GitHub Desktop.
Making stairs and a bow tie
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 makeBowTie(int h) { | |
int i, j, k, s; | |
for (i = 1; i <= h; ++i) { | |
s = 2*i-1; | |
s = h - abs(h - s); | |
for (j = 0; j < s; ++j) cout << '*'; | |
for (j = 0; j < 2*h - 2*s; ++j) cout << ' '; | |
for (j = 0; j < s; ++j) cout << '*'; | |
cout << '\n'; | |
} | |
} | |
void makeStairs(int h) { | |
int i, j, r = h/2+1; | |
for (i = 1; i <= h; ++i) { | |
int s = r - abs(r - i); | |
for (j = 0; j < s; ++j) cout << '*'; | |
cout << '\n'; | |
} | |
} | |
void StairCase(int h) { | |
for (int i = h; i >= 1; --i) { | |
for (int j = 1; j < i; ++j) cout << ' '; | |
for (int k = i; k <= h; ++k) cout << '#'; | |
cout << '\n'; | |
} | |
} | |
int main(){ | |
makeBowTie(5); | |
cout << '\n'; | |
makeStairs(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How was I able to come up with this code! I thought I wasn't good at math....