VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-find-the-perimeter-of-a-square-given-its-area/

⇱ Program to find the perimeter of a square given its area - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to find the perimeter of a square given its area

Last Updated : 18 Jan, 2024

Write a program to find the perimeter of a square given its area.

Examples:

Input: Area = 36 square units
Output: Perimeter = 24 units
Explanation: Since the area of the square is 36 square units, so the side of square will be 6 units. Therefore, the perimeter of the square will be 4 * 6 = 24 units.

Input: Area = 25 square units
Output: Perimeter = 20 units
Explanation: Since the area of the square is 25 square units, so the side of square will be 5 units. Therefore, the perimeter of the square will be 4 * 5 = 20 units.

Approach: To solve the problem, follow the below idea:

The area of a square is given by Area=side×side. We can find the side length by taking the square root of the area. Once the side length is known, the perimeter can be calculated as Perimeter=4×side.

Step-by-step algorithm:

  • Calculate the side length using the square root of the area.
  • Calculate the perimeter using the formula Perimeter=4 × side.
  • Print the calculated perimeter.

Below is the implementation of the algorithm:


Output
Perimeter: 16

Time Complexity: O(log N), because it takes O(logN) time to calculate the square root of N.
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: