Skip to content

Commit e3ccd97

Browse files
Pascals Triangle #3
1 parent bcc1bf3 commit e3ccd97

File tree

1 file changed

+37
-0
lines changed
  • arrays-strings/pascals-triangle

1 file changed

+37
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import "fmt"
4+
5+
const row int = 5
6+
7+
func buildRow(array *[]int) {
8+
aux := 0;
9+
coefficient := 1;
10+
xExponent := row;
11+
yExponent := 1;
12+
13+
for xExponent > 0 {
14+
aux = (coefficient * xExponent) / yExponent
15+
(*array)[yExponent] = aux
16+
coefficient = aux
17+
xExponent--
18+
yExponent++
19+
}
20+
}
21+
22+
func main() {
23+
array := make([]int, row + 1)
24+
array[0] = 1
25+
26+
if row == 0 {
27+
fmt.Println(array)
28+
} else if row == 1 {
29+
array[1] = 1
30+
fmt.Println(array)
31+
} else if row > 1 {
32+
buildRow(&array)
33+
fmt.Println(array)
34+
}else{
35+
fmt.Println("Only positive integer number.")
36+
}
37+
}

0 commit comments

Comments
 (0)