-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
70 lines (59 loc) · 1.54 KB
/
main.go
File metadata and controls
70 lines (59 loc) · 1.54 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"errors"
"fmt"
)
func main(){
printMe()
var printValue string = "Parameter function is called"
printWithParam(printValue)
var numerator int = 11
var denominator int = 2
var result, remainder, err = intDivision(numerator,denominator)
// if err!=nil{
// fmt.Print(err.Error())
// }else if remainder == 0{
// fmt.Printf("The result of the integer division is %v", result)
// }else{
// fmt.Printf("The result of the integer division is %v with remainder %v",result, remainder)
// }
switch{
case err!=nil:
fmt.Print(err.Error())
case remainder==0:
fmt.Printf("The result of the integer division is %v", result)
default:
fmt.Printf("The result of the integer division is %v with remainder %v",result, remainder)
}
switch remainder{
case 0:
fmt.Println("The divison was exact")
case 1,2:
fmt.Println("The division was close")
default:
fmt.Println("The division was not close")
}
}
func printMe(){
fmt.Println("Hi! This is the function that we defined")
}
func printWithParam(printValue string){
fmt.Println(printValue)
}
func intDivision(numerator int, denominator int) (int, int, error) {
var err error
if denominator == 0{
err = errors.New("cannot divide by zero")
return 0, 0 , err
}
var result int = numerator/denominator
var remainder int = numerator%denominator
return result, remainder, err
}
/*
>>>>>>>>>>> go run tutorial3/main.go
O/p::::
Hi! This is the function that we defined
Parameter function is called
The result of the integer division is 5 with remainder 1The division was close
*/