# Pascal's Triangle

Page 1 of 1

## 0 Replies - 5900 Views - Last Post: 08 December 2012 - 08:12 AM

### #1 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12648
• Posts: 45,822
• Joined: 27-December 08

# Pascal's Triangle

Posted 08 December 2012 - 08:12 AM

Description: Invoke pascalRow(), and pass it some int value. Examples:
pascalRow(3);
pascalRow(5);Returns the nth row of Pascal's Triangle
```    /**
*
* @param row The ith row of the Pascal Triangle
* @return ArrayList<Integer> A List containing all the binomial coefficients
*         for the given row
*/
public ArrayList<Integer> pascalRow(int row){
ArrayList<Integer> values = new ArrayList<Integer>();

for(int i = 0; i <= row; i++){
}

return values;

}

/**
*
* @param n The number of total elements
* @param r The number to choose from n
* @return The binomial coefficient n!/(r! * (n-r)!)
*/
public int choose(int n, int r){
return factorial(n)/(factorial(r) * factorial(n-r));
}

/**
*
* @param n The number of which to take the factorial
* @return int n!
*/
public int factorial(int n){
int x = 1;

for(int i = 2; i <= n; i++){
x *= i;
}

return x;
}

```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }