dimanche 4 novembre 2018

How to integrate a row in pascal's triangle?

I have a pascal's triangle with max rows of 5 . Lets suppose I want to find the integration of the fourth row . How do I access the fourth row in the pascal's triangle. More precisely I want to know how to access a row in the pascal's triangle by entering the number n of the row

Code

#include <iostream>

using namespace std;

int main(){

    int a1, a2, a3, a4, a5, pascal, columns;
    const int rows = 5;

    int **array = new int *[rows]; //generating array
    for(int i = 0; i <= rows; i++)
    array[i] = new int [columns];

    for (int i = 0; i <= rows; i++){  //loop for te pascal's triangle
        for (int j = 0; j <= i; j++){
            if(j == 0 || i == 0){
                pascal = 1;  //first element of pascal's triangle
            }
            else{
                pascal = pascal *(i - j + 1) / j; //pascal's triangle formula
            }
            cout << "  " << pascal; // printing pascals triangle
         }
         cout << "\n";
    }
    cout << "enter which row to intergrate: ";
    // here I want to directly access a row rather that entering the elements of the row 
    cin >> a1;
    cin >> a2;
    cin >> a3;
    cin >> a4;
    cin >> a5;

 }

Aucun commentaire:

Enregistrer un commentaire