-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtuples.go
More file actions
50 lines (31 loc) · 721 Bytes
/
tuples.go
File metadata and controls
50 lines (31 loc) · 721 Bytes
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
48
49
50
//main package has examples shown
// in Go Data Structures and algorithms book
package main
// importing fmt package
import (
"fmt"
)
//gets the powerseries of integer a and returns tuple of square of a
// and cube of a
func powerSeries(a int) (int, int) {
return a * a, a * a * a
}
func powerSeriesN(a int) (square int, cube int) {
square = a * a
cube = square * a
return
}
func powerSeriesE(a int) (int, int, error) {
var square int = a * a
var cube int = square * a
return square, cube, nil
}
// main method
func main() {
var square int
var cube int
square, cube = powerSeries(3)
fmt.Println("Square ", square, "Cube", cube)
fmt.Println(powerSeriesN(4))
fmt.Println(powerSeriesE(5))
}