GO练习题

 

package main


import(
	"fmt"
)

func list(n int) {

	for i := 0; i <= n; i++ {
		fmt.Printf("%d+%d=%d\n", i, n - i, n)
	}
}


func main() {

	list(10)
}

  

 

 

package main

import(
	a "go_dev/day2/example2/add"
	"fmt"
)


func main() {
	
	fmt.Println("Name=", a.Name)
	fmt.Println("age=", a.Age)
}

3.  

写一个程序,交换两个整数的值。比如: a=3; b=4; 交换之后:a=4;b=3

package main

import "fmt"

func swap(a *int, b *int) {
	tmp := *a
	*a = *b
	*b = tmp
	return
}

func swap1(a int, b int) (int, int) {
	return b, a
}

func test() {
	var a = 100
	fmt.Println(a)
	//var b int
	for i := 0; i < 100; i++ {
		var b = i * 2
		fmt.Println(b)
	}

	//fmt.Println(c)
	//fmt.Println(b)
}

func test2() {
	var a int8 = 100
	var b int16 = int16(a)

	fmt.Printf("a=%d b=%d\n", a, b)
}

func main() {
	first := 100
	second := 200
	//swap(&first, &second)
	//first, second = swap1(first, second)
	first, second = second, first
	fmt.Println("first=", first)
	fmt.Println("second=", second)

	test()

	test2()
}

  

 

posted @ 2020-08-21 15:46  lcsp  阅读(165)  评论(0编辑  收藏  举报