Functions

Reading material

Go by example: Functions

A Tour of Go: Functions


First exercise


// functions1
// Make me compile!

// I AM NOT DONE
package main

func main() {
	call_me()
}

Second exercise

// functions2
// Make me compile!

// I AM NOT DONE
package main

import "fmt"

func main() {
	call_me(10)
}

func call_me(num) {
	for n := 0; n <= num; n++ {
		fmt.Printf("Num is %d\n", n)
	}
}

Third exercise

// functions3
// Make me compile!

// I AM NOT DONE
package main

import "fmt"

func main() {
	call_me()
}

func call_me(num int) {
	for n := 0; n <= num; n++ {
		fmt.Printf("Num is %d\n", n)
	}
}

Fourth exercise

// functions4
// Make me compile!

// I AM NOT DONE
package main

import "fmt"

func main() {
	fmt.Println("1 + 2 is: ", add_numbers(1, 2)) // don't change this line
}

func add_numbers(a int, b int) {
	return a + b
}


If something is wrong in this page, edit this page on GitHub