![]() |
VOOZH | about |
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:
Below is the implementation of the algorithm:
Perimeter: 16
Time Complexity: O(log N), because it takes O(logN) time to calculate the square root of N.
Auxiliary Space: O(1)