Calculate area of square

Here given code implementation process.

//C Program
//Calculate Area of Square
#include <stdio.h>

///Calculate area of Square by given side
void square_area(double side)
{
	//Calculate area of square
	double area = (side * side);
	//Display the result of Square area
	printf(" Square  [ side : %lf ] ", side);
	printf("\n Area : %lf\n\n", area);
}
int main()
{
	//Test Cases  
	square_area(5);
	square_area(8);
	square_area(7.5);
	return 0;
}

Output

 Square  [ side : 5.000000 ]
 Area : 25.000000

 Square  [ side : 8.000000 ]
 Area : 64.000000

 Square  [ side : 7.500000 ]
 Area : 56.250000
// Java Program
// Calculate Area of Square
class SquareSize
{
	///Calculate area of square by given side
	public void square_area(double side)
	{
		//Calculate area of square
		double area = (side * side);
		//Display the result of square area
		System.out.print(" Square [ side : " + side + " ] ");
		System.out.print("\n Area : " + area + "\n\n");
	}
	public static void main(String[] args)
	{
		SquareSize obj = new SquareSize();
		//Test Cases  
		obj.square_area(5);
		obj.square_area(8);
		obj.square_area(7.5);
	}
}

Output

 Square [ side : 5.0 ]
 Area : 25.0

 Square [ side : 8.0 ]
 Area : 64.0

 Square [ side : 7.5 ]
 Area : 56.25
// C++ Program
// Calculate Area of Square
#include<iostream>

using namespace std;
class SquareSize
{
	public:
		///Calculate area of square by given side
		void square_area(double side)
		{
			//Calculate area of square
			double area = (side *side);
			cout << " Square [ side : " << side << " ] ";
			cout << "\n Area : " << area << "\n\n";
		}
};
int main()
{
	SquareSize obj = SquareSize();
	//Test Cases  
	obj.square_area(5);
	obj.square_area(8);
	obj.square_area(7.5);
	return 0;
}

Output

 Square [ side : 5 ]
 Area : 25

 Square [ side : 8 ]
 Area : 64

 Square [ side : 7.5 ]
 Area : 56.25
// C# Program
// Calculate Area of Square
using System;
class SquareSize
{
	///Calculate area of square by given side
	public void square_area(double side)
	{
		//Calculate area of square
		double area = (side * side);
		Console.Write(" Square [ side : " + side + " ] ");
		Console.Write("\n Area : " + area + "\n\n");
	}
	public static void Main(String[] args)
	{
		SquareSize obj = new SquareSize();
		//Test Cases  
		obj.square_area(5);
		obj.square_area(8);
		obj.square_area(7.5);
	}
}

Output

 Square [ side : 5 ]
 Area : 25

 Square [ side : 8 ]
 Area : 64

 Square [ side : 7.5 ]
 Area : 56.25
<?php
// Php Program
// Calculate Area of Square
class SquareSize
{
	///Calculate area of square by given side
	public 	function square_area($side)
	{
		//Calculate area of square
		$area = ($side *$side);
		//Display the result of square area
		echo(" Square [ side : ". $side ." ] ");
		echo("\n Area : ". $area ."\n\n");
	}
}

function main()
{
	$obj = new SquareSize();
	//Test Cases  
	$obj->square_area(5);
	$obj->square_area(8);
	$obj->square_area(7.5);
}
main();

Output

 Square [ side : 5 ]
 Area : 25

 Square [ side : 8 ]
 Area : 64

 Square [ side : 7.5 ]
 Area : 56.25
// Node Js Program
// Calculate Area of Square
class SquareSize
{
	///Calculate area of square by given side
	square_area(side)
	{
		//Calculate area of square
		var area = (side *side);
		//Display the result of square area
		process.stdout.write(" Square [ side : " + side + " ] ");
		process.stdout.write("\n Area : " + area + "\n\n");
	}
}

function main(args)
{
	var obj = new SquareSize();
	//Test Cases  
	obj.square_area(5);
	obj.square_area(8);
	obj.square_area(7.5);
}
main();

Output

 Square [ side : 5 ]
 Area : 25

 Square [ side : 8 ]
 Area : 64

 Square [ side : 7.5 ]
 Area : 56.25
#  Python 3 Program
#  Calculate Area of Square
class SquareSize :
	# /Calculate area of square by given side
	def square_area(self, side) :
		# Calculate area of square
		area = (side * side)
		# Display the result of square area
		print(" Square [ side : ", side ," ] ", end = "")
		print("\n Area : ", area ,"\n\n", end = "")
	

def main() :
	obj = SquareSize()
	# Test Cases  
	obj.square_area(5)
	obj.square_area(8)
	obj.square_area(7.5)


if __name__ == "__main__": main()

Output

 Square [ side :  5  ]
 Area :  25

 Square [ side :  8  ]
 Area :  64

 Square [ side :  7.5  ]
 Area :  56.25
#  Ruby Program
#  Calculate Area of Square
class SquareSize

	# Calculate area of square by given side
	def square_area(side)
	
		# Calculate area of square
		area = (side * side)
		# Display the result of square area
		print(" Square [ side  :", side ," ] ")
		print("\n Area  :", area ,"\n\n")
	end
end
def main()

	obj = SquareSize.new()
	# Test Cases  
	obj.square_area(5)
	obj.square_area(8)
	obj.square_area(7.5)
end
main()

Output

 Square [ side  :5 ] 
 Area  :25

 Square [ side  :8 ] 
 Area  :64

 Square [ side  :7.5 ] 
 Area  :56.25

// Scala Program
// Calculate Area of Square
class SquareSize
{
	//Calculate area of square by given side
	def square_area(side: Double): Unit = {
		//Calculate area of square
		var area: Double = (side * side);
		//Display the result of square area
		print(" Square [ side : " + side + " ] ");
		print("\n Area : " + area + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: SquareSize = new SquareSize();
		//Test Cases  
		obj.square_area(5);
		obj.square_area(8);
		obj.square_area(7.5);
	}
}

Output

 Square [ side : 5.0 ]
 Area : 25.0

 Square [ side : 8.0 ]
 Area : 64.0

 Square [ side : 7.5 ]
 Area : 56.25
// Swift Program
// Calculate Area of Square
class SquareSize
{
	//Calculate area of square by given side
	func square_area(_ side: Double)
	{
		//Calculate area of square
		let area: Double = (side * side);
		//Display the result of square area
		print(" Square [ side : ", side ," ] ", terminator: "");
		print("\n Area : ", area ,"\n\n", terminator: "");
	}
}
func main()
{
	let obj: SquareSize = SquareSize();
	//Test Cases  
	obj.square_area(5);
	obj.square_area(8);
	obj.square_area(7.5);
}
main();

Output

 Square [ side :  5.0  ]
 Area :  25.0

 Square [ side :  8.0  ]
 Area :  64.0

 Square [ side :  7.5  ]
 Area :  56.25


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved