Swift Program to Find the Surface area and Volume of Cuboid


This tutorial will discuss how to write a swift program to find the surface area and volume of cuboid.

A Cuboid is a 3-dimensional solid figure which contains six rectangular faces, eight vertices and twelve edges. It has three dimensions known as length, breadth, and height and if a cuboid has integer edges then the cuboid is the perfect cuboid. The opposite edges of the cuboid are always parallel to each other and the angle formed by all vertices are 90 degrees


Surface area of cuboid

Surface area of a cuboid is the total space occupied by the cuboid. Or we can say that the total area of all the surfaces is known as the surface area of cuboid. It is of two types −

  • Total surface area − The sum of the area of all 6 faces of a cuboid is known as the total surface area of the cuboid.

  • Lateral surface area − The sum of the area of all the faces of a cuboid excluding the base and top is known as the lateral surface area of the cuboid. Or we can say that the lateral surface area of a cuboid is the sum of the area of four vertical faces.

Total surface area

Formula

Following is the formula of Total surface area of cuboid −

S.A = 2[(length x breadth) + (length x height) + (breadth x height)]

Algorithm to find Total Surface Area

  • Step 1 − Define three variables (Length, Breadth, Height)

  • Step 2 − Assign the value of those variables

  • Step 3 − Implement Total Surface Area Formula (2[(length x breadth) + (length x height) + (breadth x height)])

  • Step 4 − Print the output

Example

The following program shows how to calculate the total surface area of cuboid.

import Foundation import Glibc var length = 60 var breadth = 10 var height = 10 var surfaceAreaOfCuboid = 2 * ((length * breadth) + (length * height) + (breadth * height)) print("Length of cuboid is - ", length) print("Breadth of cuboid is - ", breadth) print("Height of cuboid is -", height) print("\nFinal surface area of the cuboid is - ", surfaceAreaOfCuboid)

Output

Length of cuboid is - 60
Breadth of cuboid is - 10
Height of cuboid is - 10
Final surface area of the cuboid is - 2600

In the above code, we find the total surface area of a cuboid using the mathematical formula as shown in the below code −

var surfaceAreaOfCuboid = 2 * ((length * breadth) + (length * height) + (breadth * height))

Here, the length, breadth, and height of a cuboid are 60, 10, and 10. So the total surface area of a cuboid is 2600.

Lateral surface area

Formula

Following is the formula for lateral surface area of a cuboid −

S.A = 2 x height x [(length + breadth)]

Algorithm to find Lateral surface area

  • Step 1 − Define three variables (Length, Breadth, Height)

  • Step 2 − Assign the value of those variables

  • Step 3 − Implement Total Surface Area Formula (2 x height x [(length + breadth)])

  • Step 4 − Print the output

Example

The following program shows how to calculate the lateral surface area of cuboid.

import Foundation import Glibc var length = 50 var breadth = 20 var height = 20 var LateralsurfaceAreaOfCuboid = 2 * height * (length + breadth) print("Length of cuboid is - ", length) print("Breadth of cuboid is - ", breadth) print("Height of cuboid is -", height) print("\nLateral Surface Area is - ", LateralsurfaceAreaOfCuboid)

Output

Length of cuboid is - 50 
Breadth of cuboid is - 20 
Height of cuboid is - 20
Lateral Surface Area is - 2800

In the above code, we find the lateral surface area of a cuboid using the mathematical formula as shown in the below code −

var LateralsurfaceAreaOfCuboid = 2 * height * (length + breadth)

Here, the length, breadth, and height of a cuboid are 50, 20, and 20. So the lateral surface area of a cuboid is 2800.

Volume of cuboid

The volume of the cuboid is the amount of space acquired by the cuboid and depends upon its three dimensions that are length, breadth, and height. So the volume of the cuboid is the product of its three dimensions (length, breadth, and height).

Formula

Following is the formula of the volume of a cuboid −

V = length x breadth x height

Algorithm to find Volume of cuboid

  • Step 1 − Define three variables (Length, Breadth, Height)

  • Step 2 − Assign the value of those variables

  • Step 3 − Implement Volume of cuboid Formula (length x breadth x height)

  • Step 4 − Print the output

Example

The following program shows how to calculate the volume of a cuboid.

import Foundation import Glibc var length = 70 var breadth = 20 var height = 20 var volumeOfCuboid = length * breadth * height print("Length of cuboid is - ", length) print("Breadth of cuboid is - ", breadth) print("Height of cuboid is -", height) print("Cuboid’s volume - ", volumeOfCuboid)

Output

Length of cuboid is - 70 
Breadth of cuboid is - 20 
Height of cuboid is - 20
Cuboid’s volume - 28000

In the above code, we find the volume of a cuboid using the mathematical formula as shown in the below code −

var volumeOfCuboid = length * breadth * height

Here, the length, breadth, and height of a cuboid are 70, 20, and 20. So the volume of a cuboid is 28000.

Updated on: 01-Aug-2022

581 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements