Given one of the Sides **S**, Diagonal **D**, or Perimeter **P** of the square, the task is to find the area of the square with the given value.

**Examples:**

Input:S = 5Output:Area of the square using side = 25

Input:D = 4Output:Area of the square using diagonal = 8

Input:P = 32Output:Area of the square using perimeter = 64

### Finding Area of Square using its Side

The area of the square of the side **S** is given by:

Area = Side * Side

Below is the implementation of the above approach:

## C++

`// C++ program for the above approach` `#include <iostream>` `using` `namespace` `std;` `// Function to find the area of a square` `int` `areaOfSquare(` `int` `S)` `{` ` ` `// Use above formula` ` ` `int` `area = S * S;` ` ` `return` `area;` `}` `// Driver Code` `int` `main()` `{` ` ` `// Given Side of square` ` ` `int` `S = 5;` ` ` `// Function call` ` ` `cout << areaOfSquare(S);` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Java program for the above approach` `class` `GFG{` ` ` `// Function to find the area of a square` `static` `int` `areaOfSquare(` `int` `S)` `{` ` ` `// Use above formula` ` ` `int` `area = S * S;` ` ` ` ` `return` `area;` `}` ` ` `// Driver Code` `public` `static` `void` `main(String[] args)` `{` ` ` ` ` `// Given Side of square` ` ` `int` `S = ` `5` `;` ` ` ` ` `// Function call` ` ` `System.out.println(areaOfSquare(S));` `}` `}` `// This code is contributed by rock_cool` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program for the above approach` `# Function to find the area of a square` `def` `areaOfSquare(S):` ` ` `# Use above formula` ` ` `area ` `=` `S ` `*` `S` ` ` `return` `area` `# Driver Code` `if` `__name__ ` `=` `=` `'__main__'` `:` ` ` `# Given Side of square` ` ` `S ` `=` `5` ` ` `# Function call` ` ` `print` `(areaOfSquare(S))` `# This code is contributed by Mohit Kumar` |

*chevron_right*

*filter_none*

## C#

`// C# program for the above approach` `using` `System;` `class` `GFG{` ` ` `// Function to find the area of a square` `static` `int` `areaOfSquare(` `int` `S)` `{` ` ` `// Use above formula` ` ` `int` `area = S * S;` ` ` ` ` `return` `area;` `}` ` ` `// Driver Code` `public` `static` `void` `Main(` `string` `[] args)` `{` ` ` ` ` `// Given Side of square` ` ` `int` `S = 5;` ` ` ` ` `// Function call` ` ` `Console.Write(areaOfSquare(S));` `}` `}` `// This code is contributed by Ritik Bansal` |

*chevron_right*

*filter_none*

**Output:**

25

### Finding Area of Square using its Diagonal

- The Area of the square of given side
**S**is given by:

Area = S * S …(1)

- The relation between Side
**S**and Diagonal**D**is given by:

…(2)

- Substituting the value of S from Equation (2) in Equation (1), we have:

Below is the implementation of the above approach:

## C++

`// C++ program for the above approach` `#include <iostream>` `using` `namespace` `std;` `// Function to find the area of a square` `int` `areaOfSquare(` `int` `D)` `{` ` ` `// Use above formula` ` ` `int` `area = (D * D) / 2;` ` ` `return` `area;` `}` `// Driver Code` `int` `main()` `{` ` ` `// Given diagonal of square` ` ` `int` `D = 4;` ` ` `// Function call` ` ` `cout << areaOfSquare(D);` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Java program for the above approach` `import` `java.util.*;` `class` `GFG{` `// Function to find the area of a square` `static` `int` `areaOfSquare(` `int` `D)` `{` ` ` ` ` `// Use above formula` ` ` `int` `area = (D * D) / ` `2` `;` ` ` `return` `area;` `}` `// Driver Code` `public` `static` `void` `main(String[] args)` `{` ` ` ` ` `// Given diagonal of square` ` ` `int` `D = ` `4` `;` ` ` `// Function call` ` ` `System.out.print(areaOfSquare(D));` `}` `}` `// This code is contributed by PrinciRaj1992` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program for the above approach` `# Function to find the area of a square` `def` `areaOfSquare(D):` ` ` `# Use above formula` ` ` `area ` `=` `(D ` `*` `D) ` `/` `/` `2` `;` ` ` `return` `area;` `# Driver Code` `if` `__name__ ` `=` `=` `'__main__'` `:` ` ` `# Given diagonal of square` ` ` `D ` `=` `4` `;` ` ` `# Function call` ` ` `print` `(areaOfSquare(D));` `# This code is contributed by PrinciRaj1992` |

*chevron_right*

*filter_none*

## C#

`// C# program for the above approach` `using` `System;` `class` `GFG{` `// Function to find the area of a square` `static` `int` `areaOfSquare(` `int` `D)` `{` ` ` ` ` `// Use above formula` ` ` `int` `area = (D * D) / 2;` ` ` `return` `area;` `}` `// Driver Code` `public` `static` `void` `Main(String[] args)` `{` ` ` ` ` `// Given diagonal of square` ` ` `int` `D = 4;` ` ` `// Function call` ` ` `Console.Write(areaOfSquare(D));` `}` `}` `// This code is contributed by amal kumar choubey` |

*chevron_right*

*filter_none*

**Output:**

8

### Finding Area of Square using its Perimeter

- The Area of the square of given side
**S**is given by:

Area = S * S …(1)

- The relation between Side
**S**and Perimeter**P**is given by:

P =4*S …(2)

- Substituting the value of S from Equation (2) in Equation (1), we have:

Below is the implementation of the above formula:

## C++

`// C++ program for the above approach` `#include <iostream>` `using` `namespace` `std;` `// Function to find the area of a square` `int` `areaOfSquare(` `int` `P)` `{` ` ` `// Use above formula` ` ` `int` `area = (P * P) / 16;` ` ` `return` `area;` `}` `// Driver Code` `int` `main()` `{` ` ` `// Given perimeter of square` ` ` `int` `P = 32;` ` ` `// Function call` ` ` `cout << areaOfSquare(P);` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Java program for the above approach` `class` `GFG{` `// Function to find the area of a square` `static` `int` `areaOfSquare(` `int` `P)` `{` ` ` ` ` `// Use above formula` ` ` `int` `area = (P * P) / ` `16` `;` ` ` `return` `area;` `}` `// Driver Code` `public` `static` `void` `main(String[] args)` `{` ` ` ` ` `// Given perimeter of square` ` ` `int` `P = ` `32` `;` ` ` `// Function call` ` ` `System.out.print(areaOfSquare(P));` `}` `}` `// This code is contributed by amal kumar choubey ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program for the above approach` `# Function to find the area of a square` `def` `areaOfSquare(P):` ` ` ` ` `# Use above formula` ` ` `area ` `=` `(P ` `*` `P) ` `/` `/` `16` `;` ` ` `return` `area;` `# Driver Code` `if` `__name__ ` `=` `=` `'__main__'` `:` ` ` ` ` `# Given perimeter of square` ` ` `P ` `=` `32` `;` ` ` `# Function call` ` ` `print` `(areaOfSquare(P));` `# This code is contributed by gauravrajput1` |

*chevron_right*

*filter_none*

## C#

`// C# program for the above approach` `using` `System;` `class` `GFG{` `// Function to find the area of a square` `static` `int` `areaOfSquare(` `int` `P)` `{` ` ` ` ` `// Use above formula` ` ` `int` `area = (P * P) / 16;` ` ` `return` `area;` `}` `// Driver Code` `public` `static` `void` `Main(String[] args)` `{` ` ` ` ` `// Given perimeter of square` ` ` `int` `P = 32;` ` ` `// Function call` ` ` `Console.Write(areaOfSquare(P));` `}` `}` `// This code is contributed by amal kumar choubey` |

*chevron_right*

*filter_none*

**Output:**

64

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Program to calculate area of a rhombus whose one side and diagonal are given
- Area of a square from diagonal length
- Length of a Diagonal of a Parallelogram using the length of Sides and the other Diagonal
- Find side of Square which makes minimal area to fit two identical rectangles inside it
- Program for Area And Perimeter Of Rectangle
- Program to calculate area and perimeter of Trapezium
- Program to calculate area and perimeter of equilateral triangle
- Area and Perimeter of Rectangle in PL/SQL
- Program to find the Area and Perimeter of a Semicircle
- Program to calculate area and perimeter of a rhombus whose diagonals are given
- Find maximum volume of a cuboid from the given perimeter and area
- Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle
- Perimeter and Area of Varignon's Parallelogram
- Program to find Perimeter / Circumference of Square and Rectangle
- Maximum area of rectangle possible with given perimeter
- Find the side of the squares which are lined in a row, and distance between the centers of first and last square is given
- Find the area of quadrilateral when diagonal and the perpendiculars to it from opposite vertices are given
- Find the area of rhombus from given Angle and Side length
- Area of hexagon with given diagonal length

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.