package main
import("fmt""math")type Circle struct{
radius float64}func(r *Circle)Area()float64{return math.Pi * r.radius * r.radius
}func(r *Circle)Perimeter()float64{return2* math.Pi * r.radius
}funcmain(){var radius float64
fmt.Printf("Enter radius of the circle: ")
fmt.Scanf("%f",&radius)
c := Circle{radius: radius}
fmt.Printf("Area of the circle is: %.2f\n", c.Area())
fmt.Printf("Perimeter of the circle is: %.2f\n", c.Perimeter())}
Go
输出
Enter radius of the circle:7
Area of the circle is:153.94
Perimeter of the circle is:43.98