Skip to content

Instantly share code, notes, and snippets.

@izanbf1803
Created December 31, 2018 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izanbf1803/feb3abd33fc9a1217d84755259a66b70 to your computer and use it in GitHub Desktop.
Save izanbf1803/feb3abd33fc9a1217d84755259a66b70 to your computer and use it in GitHub Desktop.
Draw Pascal's triangle with simple format
#include <bits/stdc++.h>
using namespace std;
void pascals_triangle(int n)
{
n = 1 << (n+1);
vector<vector<bool>> a;
a.resize(n);
a[0].resize(1);
a[0][0] = 1;
for (int i = 1; i < n; ++i) {
a[i].resize(i+1);
a[i][0] = a[i][i] = 1;
for (int j = 1; j <= i-1; ++j) {
a[i][j] = a[i-1][j-1] ^ a[i-1][j];
}
}
for (int i = 0; i < n; ++i) {
for (int x = 0; x < n-1-i; ++x) {
cout << ' ';
}
for (int j = 0; j <= i; ++j) {
cout << (a[i][j] ? 'O' : '.');
if (j < i) cout << ' ';
}
cout << endl;
}
}
int main()
{
pascals_triangle(3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment