# Area of a square from diagonal length

Given an number d which is length of diagonal of a square, find its area.

**Examples:**

Input : d = 10 Output : Area = 50 Input : d = 12.2 Output : Area = 74.42

Area of a square can be computed as (d * d)/2. Please see below image for details.

## C++

`// C++ Program to find the area of square ` `// when its diagonal is given. ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Returns area of square from given ` `// diagonal ` `double` `findArea(` `double` `d) ` `{ ` ` ` `return` `(d * d) / 2.0; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `double` `d = 10; ` ` ` `cout << (findArea(d)); ` ` ` `return` `0; ` `} ` ` ` `// This code is contributed by ` `// Shivi_Aggarwal ` |

*chevron_right*

*filter_none*

## C

`// C Program to find the area of square ` `// when its diagonal is given. ` `#include <stdio.h> ` ` ` `// Returns area of square from given ` `// diagonal ` `double` `findArea(` `double` `d) ` `{ ` ` ` `return` `(d * d) / 2; ` `} ` ` ` `// Driver function. ` `int` `main() ` `{ ` ` ` `double` `d = 10; ` ` ` `printf` `(` `"%.2f"` `, findArea(d)); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to find the area of square ` `// when its diagonal is given. ` ` ` `class` `GFG ` `{ ` ` ` `// Returns area of square from given ` ` ` `// diagonal ` ` ` `static` `double` `findArea(` `double` `d) ` ` ` `{ ` ` ` `return` `(d * d) / ` `2` `; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `double` `d = ` `10` `; ` ` ` `System.out.println(findArea(d)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 Program to find ` `# the area of square ` `# when its diagonal is given. ` ` ` `# Returns area of square from given ` `# diagonal ` `def` `findArea(d): ` ` ` ` ` `return` `(d ` `*` `d) ` `/` `2` ` ` `# Driver function. ` `d ` `=` `10` `print` `(` `"%.2f"` `%` `findArea(d)) ` ` ` `# This code is contributed by ` `# Smitha Dinesh Semwal ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the area of square ` `// when its diagonal is given. ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Returns area of square from given ` ` ` `// diagonal ` ` ` `static` `double` `findArea(` `double` `d) ` ` ` `{ ` ` ` `return` `(d * d) / 2; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` `double` `d = 10; ` ` ` `Console.WriteLine(findArea(d)); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to find the area of ` `// square when its diagonal is given. ` ` ` `// Returns area of square ` `// from given diagonal ` `function` `findArea( ` `$d` `) ` `{ ` ` ` `return` `(` `$d` `* ` `$d` `) / 2; ` `} ` ` ` ` ` `// Driver Code ` ` ` `$d` `= 10; ` ` ` `echo` `( findArea(` `$d` `)); ` ` ` `// This code is contributed by vt_m. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

50.00

## Recommended Posts:

- Area of hexagon with given diagonal length
- Calculate area of pentagon with given diagonal
- Program to calculate area of a rhombus whose one side and diagonal are given
- Find the area of quadrilateral when diagonal and the perpendiculars to it from opposite vertices are given
- Length of the Diagonal of the Octagon
- Find length of Diagonal of Hexagon
- Length of Diagonal of a n-sided regular polygon
- Program for Area Of Square
- Program to find the area of a Square
- Sum of Area of all possible square inside a rectangle
- Area of a Circumscribed Circle of a Square
- Area of a leaf inside a square
- Program for Area Of Square after N-th fold
- Area of square Circumscribed by Circle
- Area of the Largest square that can be inscribed in an ellipse

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.