Created
June 14, 2011 18:20
-
-
Save wingyplus/1025504 to your computer and use it in GitHub Desktop.
Pascal's Triangle
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 Factorial (n int) int { | |
if n == 0 { | |
return 1 | |
} | |
return n * Factorial (n - 1) | |
} | |
func Combination (row, column int) int { | |
return Factorial (row) / (Factorial (column) * Factorial (row - column)) | |
} | |
func main () { | |
for i := 0; i < 4; i++ { | |
for j := 0; j <= i; j++ { // column j row i | |
fmt.Printf ("%d ", Combination (i, j)) | |
} | |
} | |
fmt.Println () | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment