File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
21_interfaces/06_exercises Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import "fmt"
4+
5+ func main () {
6+ solution3 ()
7+ solution4 ()
8+ }
9+
10+ func solution3 () {
11+
12+ y := []int {10 , 200 , 30 }
13+ z := []int {10 , 200 , 300 }
14+
15+
16+ defer fmt .Println (foo (y ... ))
17+ fmt .Println (bar (z ))
18+ }
19+
20+ func foo (x ... int ) int {
21+
22+ sum := 0
23+ for _ , num := range x {
24+ sum += num
25+ }
26+ return sum
27+ }
28+
29+ func bar (x []int ) int {
30+ sum := 0
31+ for _ , num := range x {
32+ sum += num
33+ }
34+ return sum
35+ }
36+
37+
38+ //Solution 4
39+
40+ type person struct {
41+ first string
42+ last string
43+ age int
44+ }
45+
46+ func (p person ) speak () {
47+ fmt .Printf ("\n name: %s %s age: %d" , p .first , p .last , p .age )
48+
49+ }
50+
51+ func solution4 () {
52+
53+ p1 := person {
54+ "abk" ,
55+ "ku" ,
56+ 41 ,
57+ }
58+ p1 .speak ()
59+ }
You can’t perform that action at this time.
0 commit comments