Add go example programs.

This commit is contained in:
Ernie Pasveer
2023-01-29 16:45:00 -06:00
parent 26042fc453
commit 91584fabcc
6 changed files with 98 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
hellogo
+10
View File
@@ -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
+29
View File
@@ -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)
}
+1
View File
@@ -0,0 +1 @@
hellogopyramid
+10
View File
@@ -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
+47
View File
@@ -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("")
}
}