Created
December 21, 2019 15:31
-
-
Save heatblazer/e57ae9a466e37d8b33d1e7245fb9523b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Printf("Fact of 6 is %d\r\n", fact(6)) | |
for n := 1; n < 7; n++ { | |
fmt.Printf("\r\n") | |
for k := 1; k < 7; k++ { | |
fmt.Printf("[%d]", binomcoef(n-1, k-1)+binomcoef(n-1, k)) | |
} | |
} | |
} | |
func fact(val int) int { | |
if val <= 0 { | |
return 1 | |
} | |
var result int = 1 | |
for i := 1; i < val+1; i++ { | |
result *= i | |
} | |
return result | |
} | |
func binomcoef(n int, k int) int { | |
return fact(n) / (fact(k) * fact(n-k)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment