Kotlin Program to Find the Area of a Circle



In this article, we will understand how find the area of a circle. Area of a circle is calculated by using the formula ?

(pie*radius*radius)/7

Below is a demonstration of the same

Suppose our input is

Radius of the circle: 5

The desired output would be ?

The Area of Circle is: 78.57142857142857

Algorithm

  • Step 1 ? START

  • Step 2 ? Declare two variables radius and myResult

  • Step 3 ? Read the value of the radius from the user

  • Step 4 ? Calculate the area of the circle by using the formula (22*radius*radius)/7 and store the result as area

  • Step 5 ? Display the area value

  • Step 6 ? STOP

Example 1

In this example, we will find the area of a circle using the above given formulae. First. declare and set the radius

val radius = 5

Now, calculate the area of the circle and save the result in a new variable myResult

val myResult = (22 * (radius.toDouble().pow(2)))/7

Let us now see the example to get the area of a circle ?

import java.util.* import kotlin.math.pow fun main() { val radius = 5 println("The radius of the circle is defined as $radius") val myResult = (22 * (radius.toDouble().pow(2)))/7 println("Area of circle is: $myResult") }

Output

The radius of the circle is defined as 5
Area of circle is: 78.57142857142857

Example 2

In this example, we will find the area of a circle ?

import java.util.* import kotlin.math.pow fun main() { val radius = 5 println("The radius of the circle is defined as $radius") getArea(radius) } fun getArea(radius: Int) { val myResult = (22 * (radius.toDouble().pow(2)))/7 println("Area of circle is: $myResult") }

Output

The radius of the circle is defined as 5
Area of circle is: 78.57142857142857
Updated on: 2022-10-13T13:02:26+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements