Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
Last active November 30, 2024 02:41
Show Gist options
  • Save dgodfrey206/b0bacc9be9b7a289803ab94893fa0e26 to your computer and use it in GitHub Desktop.
Save dgodfrey206/b0bacc9be9b7a289803ab94893fa0e26 to your computer and use it in GitHub Desktop.
Making stairs and a bow tie
#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);
}
@dgodfrey206
Copy link
Author

How was I able to come up with this code! I thought I wasn't good at math....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment