Section5.49 - COMPLETE

This commit is contained in:
2023-10-03 14:17:13 +02:00
parent 053656ce3f
commit 3695507896
5 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
/*
Coding Exercise #1
Consider the following variable declarations:
x, y, z := 10, 15.5, "Gophers"
score := []int{10, 20, 30}
Using fmt.Printf():
Print each variable using a specific verb for its type
Print the string value enclosed by double quotes ("Gophers")
Print each variable using the same verb
Print the type of y and score
package main
import "fmt"
func main() {
x, y, z := 10, 15.5, "Gophers"
score := []int{10, 20, 30}
fmt.Printf("x is %d, y is %f, z is %s\n", x, y, z)
fmt.Printf("score is %#v\n", score)
fmt.Printf("Values are %v,%v,%v,%v \n", x, y, z, score)
fmt.Printf("y is %T\nscore is %T\n", y, score)
}
*/
/*
Coding Exercise #2
Consider the following constant declaration: const x float64 = 1.422349587101
Write a Go program that prints the value of x with 4 decimal points.
package main
import "fmt"
func main() {
const x float64 = 1.422349587101
fmt.Printf("%.4f\n", x)
}
*/
/*
Coding Exercise #3
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 "fmt"
func main() {
shape := "circle"
radius := 3.2
const pi float64 = 3.14159
circumference := 2 * pi * radius
fmt.Printf("Shape: %q\n")
fmt.Printf("Circle's circumference with radius %d is %b\n", radius, circumference)
_ = shape
}
*/
package main
import "fmt"
func main() {
shape := "circle"
radius := 3.2
const pi float64 = 3.14159
var circumference float64 = float64(2) * pi * radius
fmt.Printf("Shape: %q\n", shape)
fmt.Printf("Circle's circumference with radius %f is %f\n", radius, circumference)
}