-
Notifications
You must be signed in to change notification settings - Fork 0
/
anony_func.go
47 lines (39 loc) · 980 Bytes
/
anony_func.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// how to Anonymous Function within or outside the 'main' function
package main
import "fmt"
// create anonymous func outside the 'main' func
var outerFunction = func(x, y int) int {
value1 := x + y
return value1
}
func main() {
// create anonymous func within the 'main' func
func() {
fmt.Println("Hello world!")
}()
// add program
sum := func(x, y int) int {
arg1 := x + y
return arg1
}(14, 7)
fmt.Println(sum)
fmt.Println(" ")
/* ************************************** */
// Find Area of Triangle
var h, b int
fmt.Print("Enter Height Value: ")
fmt.Scanf("%d", &h)
fmt.Print("Enter Based Value: ")
fmt.Scanf("%d", &b)
a := func(h, b int) int {
area := (h * b) / 2
return area
}(h, b)
fmt.Println("Area of Triangle: ", a)
fmt.Println(" ")
/* -------------------------------------------- */
// create anonymous func outside the 'main' func
/* calling function */
add := outerFunction(14, 8)
fmt.Println("Sum of two number is :", add)
}