-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (77 loc) · 1.89 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"bufio"
"fmt"
"log"
"os"
)
// Anonymous functions are those functions which are used only once.
func twoValues(a, b int) (int, int) {
sum := a + b
multiply := a * b
return sum, multiply
}
func addition(num1, num2 int) int {
res := num1 + num2
fmt.Println(res)
return res
}
type Student struct {
rollNo int
name string
isVerified bool
}
func Calculator(a, b int) string {
add := a + b
sub := a - b
multi := a * b
divide := a / b
output := "addition of two numbers is " + fmt.Sprint(add) +
", subtraction of two numbers is " + fmt.Sprint(sub) +
", multiplication of two numbers is " + fmt.Sprint(multi) +
", division of two numbers is " + fmt.Sprint(divide)
return output
}
func main() {
var sushant = Student{11222631,
"saloni saroha", true}
fmt.Println(sushant.name)
resultOfCalculator := Calculator(90, 40)
fmt.Println(resultOfCalculator)
var array1 = []int{12, 34, 56, 76, 45, 23}
for i := 0; i < len(array1); i++ {
fmt.Println(array1[i])
}
arr := []string{"saloni", "susi", "tanu", "sakshi", "riya"}
for j := 0; j < len(arr); j++ {
if arr[j] == "tanu" {
continue
}
fmt.Println(arr[j])
}
reader := bufio.NewReader(os.Stdin)
fmt.Println("enter the number")
input, _ := reader.ReadString('\n')
fmt.Println("thanks for rating", input)
items := [5]string{"sugar", "tea", "coffee", "cinemon", "elaichi"}
for key, value := range items {
fmt.Println(key, value)
}
colors := map[string]string{"Red": "#ff00", "blue": "#cf89076", "green": "#wert56789"}
for color, hex := range colors {
//fmt.Println("The name of colors is ", color, "and the hexadecimal value of color is ", hex)
fmt.Println(color, hex)
}
i := 0
for i < 5 {
fmt.Println(i)
}
defer addition(23, 45)
add, product := twoValues(4, 5)
fmt.Println(add, product)
file, err := os.Open("Example.txt")
defer file.Close()
if err != nil {
log.Fatal(err)
}
}