We had written code as -
package main
import "fmt"
type Rectangle struct {
Length, Width float32
}
type Circle struct {
Radius float32
}
func (r *Rectangle) Area() float32 {
return r.Length * r.Width
}
func (r *Rectangle) Perimeter() float32 {
return 2 * (r.Length + r.Width)
}
func (c *Circle) Area() float32 {
const PI float32 = 3.144444444444
return PI * (c.Radius * c.Radius)
}
func (c *Circle ) Circumference() float32 {
const PI float32 = 3.14444444444
return 2 * (PI * c.Radius)
}
func main() {
var r Rectangle
var c Circle
var first float32
fmt.Scanln(&first)
var second float32
fmt.Scanln(&second)
var third float32
fmt.Scanln(&third)
r.Length = first
r.Width = second
c.Radius = third
fmt.Println(r.Area())
fmt.Println(r.Perimeter())
fmt.Println(c.Area())
fmt.Println(c.Circumference())
}
Here first is 5, second is 6 and third is 5.
Our issue is in circle output seems some floating issue nit sure where we went wrong hence need suggestion-
Your Output
30
22
78.611115
31.444445
Expected Output
30
22
78.53981633974483
31.41592653589793