Kotlin Program to Find the Surface Area and Volume of Cuboid

Kotlin Server Side ProgrammingProgramming

In this article, we will understand how to compute the surface area and volume the cuboid. The surface area of cuboid is calculated using the formula −

2*( length *width + width* height + height*length)

The Volume of the cuboid is calculated using the formula

length*width*height

Below is a demonstration of the same −

Suppose our input is −

length= 6;
width= 7;
height= 8;

The desired output would be −

Volume Of the Cuboid is : 336.0
Surface area Of the Cuboid is : 292.0

Algorithm

  • Step 1 − START

  • Step 2 − Declare five double values namely length, width, height, volume, surfaceArea

  • Step 3 − Define the values

  • Step 4 − Use the formula 2*( length *width + width* height + height*length) to calculate the surface area of cuboid

  • Step 5 − Use the formula length*width*height to calculate the area of the cuboid

  • Step 6 − Display the result

  • Step 7 − Stop

Example 1

In this example, we will find the Volume and Surface Area of the cuboid using the length, width and height of the cuboid. First, declare and initialize the variables length, width and height −

val length = 6
val width = 7
val height = 8

Now, using the above formulae, find the Volume of Cuboid

val volume = length * width * height

In a similar way, find the Surface Area of Cuboid

val surfaceArea =2*( length * width + width * height + height * length);

Let us now see the final example to find the Volume and Surface Area of the cuboid −

fun main() { val length = 6 val width = 7 val height = 8 println("The length, width and height of the cuboid is defined as $length, $width and $height") val volume = length * width * height val surfaceArea =2*( length * width + width * height + height * length); println("The volume of the cuboid is: $volume") println("The surface area of the cuboid is: $surfaceArea") }

Output

The length, width and height of the cuboid is defined as 6, 7 and 8
The volume of the cuboid is: 336
The surface area of the cuboid is: 292

Example 2

In this example, we will find the Surface Area and Volume of Cuboid

fun main() { val length = 6 val width = 7 val height = 8 println("The length, width and height of the cuboid is defined as $length, $width and $height") cuboid(length, width, height) } fun cuboid(length: Int, width : Int, height : Int) { val volume = length * width * height val surfaceArea =2*( length * width + width * height + height * length); println("The volume of the cuboid is: $volume") println("The surface area of the cuboid is: $surfaceArea") }

Output

The length, width and height of the cuboid is defined as 6, 7 and 8
The volume of the cuboid is: 336
The surface area of the cuboid is: 292
raja
Updated on 13-Oct-2022 13:04:44

Advertisements