- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to Create a Class and Compute the Area and Perimeter of a Circle
To compute the area and perimeter of a circle, we can take following steps −
- Define a struct with circle properties such as radius.
- Define a method to calculate the area of the circle.
- Define a method to calculate the perimeter of the circle.
- In the main method, take the user's input for circle's radius.
- Instantiate the circle with the radius.
- Print the area of the circle.
- Print the perimeter of the circle.
Example
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{ return 2 * math.Pi * r.radius } func main(){ 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()) }
Output
Enter radius of the circle: 7 Area of the circle is: 153.94 Perimeter of the circle is: 43.98
- Related Articles
- Python Program to Create a Class and Compute the Area and the Perimeter of the Circle
- Golang Program to Create a Class and Object
- How to calculate the area and perimeter of a circle in JavaScript?
- Golang Program to Create a Simple Class?
- How to Find the Perimeter of a Circle in Golang?
- Golang program to create a class inside the module
- Java Program to Find out the Area and Perimeter of Rectangle using Class Concept
- Program to find the Area and Perimeter of a Semicircle in C++
- If the perimeter and the area of a circle are numerically equal, then find the radius of the circle.
- Java Program to Find the Perimeter of a Circle
- Swift Program to Find the Perimeter of a Circle
- Haskell Program to Find the Perimeter of a Circle
- Kotlin Program to Find the Perimeter of a Circle
- How to compute the area and perimeter of an image contour using OpenCV Python?
- How to find the Area of a Circle in Golang?

Advertisements