From 82579412f3b3f19d44ae54236badab941c3258fc Mon Sep 17 00:00:00 2001 From: sebastian Date: Mon, 2 Oct 2023 14:27:17 +0200 Subject: [PATCH] Section5.47 --- Section5/47.go | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Section5/47.go diff --git a/Section5/47.go b/Section5/47.go new file mode 100644 index 0000000..92ba462 --- /dev/null +++ b/Section5/47.go @@ -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) +}