Section4.46-complete

This commit is contained in:
2023-10-02 13:54:43 +02:00
parent 873196bd02
commit 1dce153a90

View File

@@ -54,7 +54,7 @@ Coding Exercise #3
EXPECTED OUTPUT:
There are 31536000 seconds in a year.
*/
package main
import "fmt"
@@ -68,3 +68,90 @@ func main() {
var result = daysYear * hoursDay * secondsHour
fmt.Printf("Seconds in a Year %d\n", result)
}
*/
/*
Coding Exercise #4
There are an error in the following Go program. Try to identify the error, change the code and run the program without errors.
package main
func main() {
const x int = 10
// declaring a constant of type slice int ([]int)
const m = []int{1: 3, 4: 5, 6: 8}
_ = m
}
package main
func main() {
const x int = 10
// declaring a constant of type slice int ([]int)
// const m = []int{1: 3, 4: 5, 6: 8}
// You cannot declare a slice constant
// _ = m
}
*/
/*
Coding Exercise #5
There are some errors in the following Go program. Try to identify the errors, change the code and run the program without errors.
package main
import "math"
func main() {
const a int = 7
const b float64 = 5.6
const c = a * b
x := 8
const xc int = x
const noIPv6 = math.Pow(2, 128)
}
package main
// import "math"
func main() {
const a int = 7
const b float64 = 5.6
const c = float64(a) * b
x := 8
_ = x
// const xc int = x
// const noIPv6 = math.Pow(2, 128)
}
*/
/*
Coding Exercise #6
Using Iota declare the following months of the year: Jun, Jul and Aug
Jun, Jul and Aug are constant and their value is 6, 7 and 8.
*/
package main
import "fmt"
func main() {
const (
Jun = iota + 6
Jul
Aug
)
fmt.Println(Jun, Jul, Aug)
}