프로그래밍/Go 24

(최대공약수 구하기) while... 반복문 예제 with Go

Go 언어에는 while 반복문이 없으므로 for 반복문을 (while 반복문 처럼) 쓰면 된다. 소스 파일명: testWhile.go // Filename: testWhile.go // // Execute: go run testWhile.go 625 1000 // or // Compile: go build testWhile.go // Execute: ./testWhile 625 1000 package main import ( "fmt" "os" "strconv" ) // 사용법 표시 함수 func printUsing() { fmt.Printf("Using: testWhile [integer1] [integer2]\n"); fmt.Printf("This finds the greatest common di..

프로그래밍/Go 2012.06.15

if...else... 조건문 사용 예제 with Go

소스 파일명: testIf.go // Filename: testIf.go // // Execute: go run testIf.go -1.5 // or // Compile: go build testIf.go // Execute: ./testIf -1.5 package main import ( "fmt" "os" "strconv" ) // 사용법 표시 함수 func printUsing() { fmt.Printf("Using: testIf [number]\n"); fmt.Printf("This determines whether the number is positive or not.\n"); } // main 함수 func main() { var val = 0.0 if (len(os.Args) != 2) { p..

프로그래밍/Go 2012.06.15

맹령행 인자 처리 예제 with Go

Go 소스 파일에 한글이 포함되어 있으면 UTF8 인코딩으로 저장해야 한다. 소스 파일명: testArguments.go // Filename: testArguments.go // // Execute: go run testArguments.go 1 2 3 // or // Compile: go build testArguments.go // Execute: ./testArguments 1 2 3 package main import ( "fmt" // fmt.Printf 함수 사용을 위해 "os" // os.Args 사용을 위해 "strconv" // strconv.ParseFloat 함수 사용을 위해 ) func main() { var sum = 0.0; var y = 0.0 for i, x := range..

프로그래밍/Go 2012.06.15