# Accessing a row in Pascal's triangle?

Below in the code for pascal's triangle , which is not in a pyramid form because I just need the elements . After entering the number of rows and number 'n' , I need to take the nth row and then find its integrals . `The question is how can I access the nth row to do some operations on it?`

1

1 1

1 2 1

1 3 3 1------> If I want to access this row, how do I access it ?

1 4 6 4 1

Code

```
#include <iostream>
using namespace std;
int main(){
int pascal, rows, columns;
for (int i = 0; i <= rows; i++){
for (int j = 0; j <= i; j++){
if(j == 0 || i == 0){
pascal = 1;
}
else{
pascal = pascal *(i - j + 1) / j;
cout << " " << pascal;
}
cout << endl;
}
}
return 0;
}
```

### 1 Answer

You could simply store each row into a `std::vector<int>`

, then keep a list of rows in a `std::vector<std::vector<int>>`

. Then, to access the nth row after calculating the triangle, you just grab the `n`

th element of the second vector.

Jesper Juhl
posted this

## Have an answer?

JD

Before you can access

anyrow of the result you'd need tostoreit somewhere, rather than just printing it. Or know the`n`

up front, so that when you get to it you can do your calculation in addition to printing.