Created
December 31, 2018 02:44
-
-
Save izanbf1803/feb3abd33fc9a1217d84755259a66b70 to your computer and use it in GitHub Desktop.
Draw Pascal's triangle with simple format
This file contains 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 <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