Jump to content
Main menu
Main menu
move to sidebar
hide
Social
Discord
Facebook
Twitter
Explore
Languages
Tasks
Random page
Rosetta Code
Search
Search
Create account
Log in
Personal tools
Dark mode
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Pascal's triangle: Difference between revisions
Page
Discussion
English
Read
View source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
View source
View history
Refresh
General
Special pages
Printable version
Get shortened URL
← Older edit
Newer edit →
Pascal's triangle
(view source)
Revision as of 02:54, 18 May 2017
711 bytes removed
,
7 years ago
→{{header|Go}}
Revision as of 02:49, 18 May 2017
(
view source
)
rosettacode>Luis Leonel
(
→{{header|Go}}
)
← Older edit
Revision as of 02:54, 18 May 2017
(
view source
)
rosettacode>Luis Leonel
(
→{{header|Go}}
)
Newer edit →
Line 1,986:
1 2 1
1 3 3 1
</pre>
Another solution:
<lang Go>
package main
import "fmt"
func main() {
fmt.Println("Enter the number of rows: ")
var n int
fmt.Scanf("%d", &n)
for r := 0; r < n; r++ {
for i := 1; i < n-r; i++ {
fmt.Print(" ")
}
j := 0
k := 1
for j <= r {
if k%2 != 0 {
fmt.Print(C(r, j))
j++
} else {
fmt.Print(" ")
}
k++
}
for i := 1; i < n-r; i++ {
fmt.Print(" ")
}
fmt.Println()
}
}
func C(r int, j int) int {
return factorial(r) / (factorial(j) * factorial(r-j))
}
func factorial(m int) int {
if m == 0 {
return 1
} else {
return m * factorial(m-1)
}
}
</lang>
Output:
<pre>
Enter the number of rows:
5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
</pre>
Anonymous user
rosettacode>Luis Leonel
Cookies help us deliver our services. By using our services, you agree to our use of cookies.
More information
OK
Toggle limited content width