Open In App

Program to find the area of a Square

Last Updated : 16 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

What is a square ? 
Square is a flat shape, in one plane, defined by four points at the four corners. A square has four sides all of equal length, and four corners, all right angles (90 degree angles). A square is a kind of rectangle but with all sides equal. 
 


Formula : 
Area = side * side
Examples: 
 

Input : 4
Output :16

Input :8
Output :64


 


 

CPP

// CPP program to find the area of a square
#include <iostream>
using namespace std; 
  
// function to find the area
int area_fun(int side)
{
int area = side * side; 
return area;
}
  
// Driver program
int main()
{
int side = 4;
int area = area_fun(side);
cout << area;
return 0; 
}

                    

Java

// Java program to find
// the area of a square
  
class GFG
{
  
// function to find the area
static int area_fun(int side)
{
int area = side * side; 
return area;
}
  
// Driver code
public static void main(String arg[]) 
{
    int side = 4;
    int area = area_fun(side);
    System.out.println(area);
}
}
  
// This code is contributed
// by Anant Agarwal.

                    

Python3

# Python program to find
# the area of a square
  
# function to find the area
def area_fun(side):
    area = side * side 
    return area
  
# Driver program
side = 4
area = area_fun(side)
print (area)
  
# This Code is Contributed
# by Azkia Anam.

                    

C#

// C# program to find
// the area of a square
using System;
  
class GFG {
  
    // function to find the area
    static int area_fun(int side)
    {
        int area = side * side;
        return area;
    }
  
    // Driver code
    public static void Main()
    {
        int side = 4;
        int area = area_fun(side);
        Console.WriteLine(area);
    }
}
  
// This code is contributed by vt_m.

                    

PHP

<?php
// PHP program to find the 
// area of a square
  
// function to find the area
function area_fun($side)
{
    $area = $side * $side
    return $area;
}
  
// Driver program
$side = 4;
$area = area_fun($side);
echo( $area);
  
// This code is contributed
// by vt_m.
?>

                    

Javascript

<script>
  
// Javascript program to find the area of a square
  
// function to find the area
function area_fun(side)
{
  let area = side * side; 
  return area;
}
  
// Driver program
let side = 4;
let area = area_fun(side);
document.write(area);
  
// This code is contributed by Mayank Tyagi
</script>

                    

Output: 
 

16

Time complexity: O(1)

space complexity: O(1)

.
 



Similar Reads

Find area of the Circle when the area of inscribed Square is given
Given the area of a square inscribed in a circle as N, the task is to calculate the area of a circle in which the square is inscribed. Examples: Input: N = 4 Output: 6.283 Input: N = 10Output: 15.707 Approach: Consider the below image: Let the area of the square is 'A'The side of the square is given by = A**(1/2)A right-angled triangle is formed by
4 min read
Area of a triangle with two vertices at midpoints of opposite sides of a square and the other vertex lying on vertex of a square
Given a positive integer N representing the side of a square, the task is to find the area of a triangle formed by connecting the midpoints of two adjacent sides and vertex opposite to the two sides. Examples: Input: N = 10Output: 37.5 Input: N = 1Output: 0.375 Approach: The given problem can be solved based on the following observations: The one s
5 min read
Program to find the surface area of the square pyramid
Given the base length(b) and slant height(s) of the square pyramid. The task is to find the surface area of the Square Pyramid. A Pyramid with a square base, 4 triangular faces, and an apex is a square pyramid. In this figure, b – base length of the square pyramid. s – slant height of the square pyramid. h – height of the square pyramid.Examples: I
3 min read
Find area of the larger circle when radius of the smaller circle and difference in the area is given
Given two integers r and d where r is the radius of the smaller circle and d is the difference of the area of this circle with some larger radius circle. The task is to find the area of the larger circle.Examples: Input: r = 4, d = 5 Output: 55.24 Area of the smaller circle = 3.14 * 4 * 4 = 50.24 55.24 - 50.24 = 5Input: r = 12, d = 3 Output: 455.16
4 min read
Program to calculate area of an Circle inscribed in a Square
Given the side of a square. The task is to find the area of an inscribed circle in a square.Examples: Input : a = 8 Output : Area of an inscribed circle: 50.24 Input : a = 12.04 Output : Area of an inscribed circle: 113.795 Given a square i.e. all sides of a square are of equal length and all four angles are 90 degrees. Below diagram depicts an ins
4 min read
Program for Area Of Square after N-th fold
A square is a flat shape, in one plane, defined by four points at the four corners. A square has four sides all of equal length, and four corners, all right angles (90 degree angles). A square is a kind of rectangle. Given a square of side [Tex]N [/Tex]and number of folds [Tex]F [/Tex]. The task is to find the area of square after F-th fold.The fol
4 min read
Program for Area Of Square
A square is a flat shape, in one plane, defined by four points at the four corners. A square has four sides all of equal length, and four corners, all right angles (90 degree angles). A square is a kind of rectangle. Examples : Input : 4 Output :16 Input :8 Output :64 Formula [Tex]Area = side*side [/Tex] C/C++ Code // CPP program to find // the are
2 min read
Find the area of the shaded region formed by the intersection of four semicircles in a square
Given the length of the side of a square a, the task is to find the area of the shaded region formed by the intersection of four semicircles in a square as shown in the image below: Examples: Input: a = 10 Output: 57Input: a = 19 Output: 205.77 Approach: Area of the shaded region will be: Area(semicircle1) + Area(semicircle2) + Area(semicircle3) +
4 min read
Find number of square of area Z which can be built in a matrix having blocked regions
In an N * N matrix, certain rows and columns are blocked. Find the number of squares of area Z which can be built in such a matrix with the given constraints: Every cell will contribute 1 unit area and 1 cell belongs to exactly 1 sub - grid.All cells should be unblocked cell. The blocked rows and columns are represented by two arrays row[] and col[
9 min read
Find side of Square which makes minimal area to fit two identical rectangles inside it
Given height H, and width W, of a rectangle, the task is to find the side of a square of the minimum area in which two rectangles fit completely. Note: Two rectangles can touch each other by side or corner.Rectangles cannot intersect each other.Rectangles can also touch the sides of the square but must be completely inside it.The Rectangles can be
12 min read