mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 08:34:42 +08:00
Add go example programs.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
hellogo
|
||||
@@ -0,0 +1,10 @@
|
||||
.PHONY: all
|
||||
all: hellogo
|
||||
|
||||
hellogo: hellogo.go
|
||||
go build -gcflags=all="-N -l" hellogo.go
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f hellogo
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type MyStruct struct {
|
||||
x string
|
||||
i int
|
||||
f float64
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println("Hello, Go World!")
|
||||
|
||||
x := "abc"
|
||||
i := 3
|
||||
|
||||
fmt.Println(i)
|
||||
fmt.Println(x)
|
||||
|
||||
ms := &MyStruct{
|
||||
x: "cba",
|
||||
i: 10,
|
||||
f: 11.10335,
|
||||
}
|
||||
|
||||
fmt.Println(ms)
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
hellogopyramid
|
||||
@@ -0,0 +1,10 @@
|
||||
.PHONY: all
|
||||
all: hellogopyramid
|
||||
|
||||
hellogopyramid: hellogopyramid.go
|
||||
go build -gcflags=all="-N -l" hellogopyramid.go
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f hellogopyramid
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Program in Golang to print Pyramid of Numbers
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main () {
|
||||
|
||||
var rows,k,temp,temp1 int
|
||||
|
||||
fmt.Print("Enter number of rows : ")
|
||||
fmt.Scan(&rows)
|
||||
|
||||
for i := 1; i <= rows; i++ {
|
||||
|
||||
for j := 1; j <= rows-i; j++ {
|
||||
fmt.Print(" ")
|
||||
temp++
|
||||
}
|
||||
|
||||
for {
|
||||
|
||||
if ( temp <= rows-1) {
|
||||
fmt.Printf(" %d", i+k)
|
||||
temp++
|
||||
}else{
|
||||
temp1++
|
||||
fmt.Printf(" %d", (i+k-2*temp1))
|
||||
}
|
||||
|
||||
k++
|
||||
|
||||
if (k == 2*i-1) {
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
temp = 0
|
||||
temp1 = 0
|
||||
k = 0
|
||||
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user