# Swift Program to Find Area of Square

This tutorial will discuss how to write a swift program to find the area of square.

A Square is a two-dimensional closed figure with four equal side and four equal angle. It can also have two diagonals of equal length. The area of the square is known as the space that is enclosed inside the boundaries of the square. Suppose we have a square study table now the area of the square helps us to find how much cloth we required to cover the top of the table. The area of the square is the product of its two side.

## Formula

Following is the area of the square formula −

Area = Side * Side

Following is the area of the square in terms of diagonal formula −

Area = (Diagonal * Diagonal)/2

## Algorithm to find the Area of the Square −

• Step 1 − Define Side_value

• Step 2 − Enter the value of Side_value

• Step 3 − Enter the formula − Side_value*Side_value

• Step 4 − Print the output

## Area of Square Program

The following program shows how to calculate the area of the square.

import Foundation
import Glibc

var sideValue = 20

var areaOfSquare = sideValue * sideValue

print("Side of the square is:", sideValue)
print("So the area is:", areaOfSquare)

## Output

Side of the square is: 20
So the area is: 400

In the above code, we calculate the area of the square with the help of the sides using the following code −

var areaOfSquare = sideValue * sideValue

Here the diagonal of the square is 20. So the area of the square is 400.

## Algorithm to find the Area of the Square Diagonally

• Step 1 − Define diagonal

• Step 2 − Enter the value of diagonal

• Step 3 − Enter the formula − (diagonal * diagonal)/2

• Step 4 − Print the output

## Example

Area of Square in terms of diagonal

The following program shows how to calculate the area of the circle with the help of the diagonal.

import Foundation
import Glibc

var diagonal = 15
var areaOfSquare = (diagonal * diagonal)/2

print("Diagonal of the square is:", diagonal)
print("So the area is:", areaOfSquare)

## Output

Diagonal of the square is: 15
So the area is: 112

In the above code, we calculate the area of the square with the help of the diagonal using the following code −

var areaOfSquare = (diagonal * diagonal)/2

Here the diagonal of the square is 15.0. So the area of the square is 112.

Updated on: 28-Jul-2022

1K+ Views 