zoukankan      html  css  js  c++  java
  • GO练习题

    package main
    
    
    import(
    	"fmt"
    )
    
    func list(n int) {
    
    	for i := 0; i <= n; i++ {
    		fmt.Printf("%d+%d=%d
    ", 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
    ", 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()
    }
    

      

  • 相关阅读:
    bzoj 1497 最小割模型
    bzoj 1024 暴力深搜
    POJ1163(简单的DP)
    POJ3287(BFS水题)
    N皇后问题(DFS)
    BFS求解迷宫的最短路径问题
    poj2386(简单的dfs/bfs)
    Fence Repair(poj3253)
    Best cow Line(POJ 3617)
    全排列
  • 原文地址:https://www.cnblogs.com/csp813/p/12894518.html
Copyright © 2011-2022 走看看