Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmProgram to find the area of a Square

Program to find the area of a Square

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)
This article is contributed by Ajay Puri. If you like neveropen and would like to contribute, you can also write an article using write.neveropen.co.za or mail your article to review-team@neveropen.co.za. See your article appearing on the neveropen main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above..
 

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments