Kotlin Program to Find the Perimeter of a Circle


In this article, we will understand how to find the perimeter of a circle. The perimeter of a circle is calculated using the formula.

(2*22*radius)/7

You can also write the above as −

2ℼr

The value of ℼ is 22/7 or 3.14.

Suppose our input is −

Radius of the circle : 5

The desired output would be −

Perimeter of Circle is: 31.428571428571427

Algorithm

  • Step 1 − START.

  • Step 2 − Declare 2 double values namely radius and myResult.

  • Step 3 − Define the values.

  • Step 4 − Calculate the perimeter using the formula using the formula (2*22*radius)/7 and store the result.

  • Step 5 − Display the result.

  • Step 6 − Stop.

Example 1

In this example, we will find the Perimeter of a Circle. First, declare and initialize a variable for the radius of the Circle −

val radius = 5

Now, in a new variable myResult, calculate the Perimeter using the above formulae −

val myResult = (2 * 22 * radius)/7

Let us now see the compete example to find the perimeter of the circle −

fun main() { val radius = 5 println("The radius of the circle is defined as $radius") val myResult = (2 * 22 * radius)/7 println("The perimeter of the circle is: $myResult") }

Output

The radius of the circle is defined as 5
The perimeter of the circle is: 31

Example 2

In this example, we will find the Perimeter of a Circle.

fun main() { val radius = 5 println("The radius of the circle is defined as $radius") circlePerimeter(radius) } fun circlePerimeter(radius: Int) { val myResult = (2 * 22 * radius)/7 println("The perimeter of the circle is: $myResult") }

Output

The radius of the circle is defined as 5
The perimeter of the circle is: 31

Updated on: 17-Oct-2022

338 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements