Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int ** buildPascal(int x);
- int main()
- {
- int x;
- cout << "Podej n: ";
- cin >> x;
- cout << "Podales: " << x <<endl;
- int **a = buildPascal(x);
- for(int i = 0; i < x; i++){
- for(int j = 0; j < x; j++){
- cout << a[j][i] << " ";
- }
- cout <<endl;
- }
- return 0;
- }
- int ** buildPascal(int x){
- int** a = new int*[x];
- for(int i = 0; i < x; ++i){
- a[i] = new int[x];
- }
- for(int i = 0; i < x; i++){
- for(int j = 0; j < x; j++){
- if(j == 0){
- a[j][i] = 1;
- }
- else{
- a[j][i] = 0;
- }
- }
- }
- for(int i = 0; i < x; i++){
- for(int j = 0; j < x; j++){
- if(i-1 >= 0 && j-1 >= 0){
- a[j][i] = a[j-1][i-1] + a[j][i-1];
- }
- }
- }
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement