Find area of parallelogram

Here given code implementation process.

// C Program
// Find area of parallelogram
#include <stdio.h>

//Calculate area of parallelogram by given altitude and base
void parallelogram_area(double altitude, double base)
{
	//Calculate area of parallelogram
	double area = base * altitude;
	//Display the result of parallelogram area
	printf(" Parallelogram Size [ base : %lf, altitude : %lf ] ", base, altitude);
	printf("\n Parallelogram Area : %lf\n\n", area);
}
int main()
{
	//Test Cases  
	parallelogram_area(3.9, 8.8);
	parallelogram_area(5.1, 11.2);
	parallelogram_area(4, 10);
	parallelogram_area(1.6, 2);
	return 0;
}

Output

 Parallelogram Size [ base : 8.800000, altitude : 3.900000 ]
 Parallelogram Area : 34.320000

 Parallelogram Size [ base : 11.200000, altitude : 5.100000 ]
 Parallelogram Area : 57.120000

 Parallelogram Size [ base : 10.000000, altitude : 4.000000 ]
 Parallelogram Area : 40.000000

 Parallelogram Size [ base : 2.000000, altitude : 1.600000 ]
 Parallelogram Area : 3.200000
/*
  Java program
  Find area of parallelogram
*/
public class Parallelogram
{
	//Calculate area of parallelogram by given altitude and base
	public void parallelogram_area(double altitude, double base)
	{
		//Calculate area of parallelogram
		double area = base * altitude;
		//Display the result of parallelogram area
		System.out.print(" Parallelogram Size [ base : " + base + ", altitude : " + altitude + " ] ");
		System.out.print("\n Parallelogram Area : " + area + "\n\n");
	}
	public static void main(String[] args)
	{
		Parallelogram obj = new Parallelogram();
		//Test Cases  
		obj.parallelogram_area(3.9, 8.8);
		obj.parallelogram_area(5.1, 11.2);
		obj.parallelogram_area(4, 10);
		obj.parallelogram_area(1.6, 2);
	}
}

Output

 Parallelogram Size [ base : 8.8, altitude : 3.9 ] 
 Parallelogram Area : 34.32

 Parallelogram Size [ base : 11.2, altitude : 5.1 ] 
 Parallelogram Area : 57.11999999999999

 Parallelogram Size [ base : 10.0, altitude : 4.0 ] 
 Parallelogram Area : 40.0

 Parallelogram Size [ base : 2.0, altitude : 1.6 ] 
 Parallelogram Area : 3.2
/*
  C++ program
  Find area of parallelogram
*/
#include<iostream>

using namespace std;
class Parallelogram
{
	public:
		//Calculate area of parallelogram by given altitude and base
		void parallelogram_area(double altitude, double base)
		{
			//Calculate area of parallelogram
			double area = base *altitude;
			cout << " Parallelogram Size [ base : " << base << ", altitude : " << altitude << " ] ";
			cout << "\n Parallelogram Area : " << area << "\n\n";
		}
};
int main()
{
	Parallelogram obj =  Parallelogram();
	//Test Cases  
	obj.parallelogram_area(3.9, 8.8);
	obj.parallelogram_area(5.1, 11.2);
	obj.parallelogram_area(4, 10);
	obj.parallelogram_area(1.6, 2);
	return 0;
}

Output

 Parallelogram Size [ base : 8.8, altitude : 3.9 ]
 Parallelogram Area : 34.32

 Parallelogram Size [ base : 11.2, altitude : 5.1 ]
 Parallelogram Area : 57.12

 Parallelogram Size [ base : 10, altitude : 4 ]
 Parallelogram Area : 40

 Parallelogram Size [ base : 2, altitude : 1.6 ]
 Parallelogram Area : 3.2
/*
  C# program
  Find area of parallelogram
*/
using System;
public class Parallelogram
{
	//Calculate area of parallelogram by given altitude and base
	public void parallelogram_area(double altitude, double base_side)
	{
		//Calculate area of parallelogram
		double area = base_side * altitude;
		Console.Write(" Parallelogram Size [ base : " + base_side + ", altitude : " + altitude + " ] ");
		Console.Write("\n Parallelogram Area : " + area + "\n\n");
	}
	public static void Main(String[] args)
	{
		Parallelogram obj = new Parallelogram();
		//Test Cases  
		obj.parallelogram_area(3.9, 8.8);
		obj.parallelogram_area(5.1, 11.2);
		obj.parallelogram_area(4, 10);
		obj.parallelogram_area(1.6, 2);
	}
}

Output

 Parallelogram Size [ base : 8.8, altitude : 3.9 ]
 Parallelogram Area : 34.32

 Parallelogram Size [ base : 11.2, altitude : 5.1 ]
 Parallelogram Area : 57.12

 Parallelogram Size [ base : 10, altitude : 4 ]
 Parallelogram Area : 40

 Parallelogram Size [ base : 2, altitude : 1.6 ]
 Parallelogram Area : 3.2
<?php
/*
  Php program
  Find area of parallelogram
*/
class Parallelogram
{
	//Calculate area of parallelogram by given altitude and base
	public 	function parallelogram_area($altitude, $base)
	{
		//Calculate area of parallelogram
		$area = $base *$altitude;
		//Display the result of parallelogram area
		echo(" Parallelogram Size [ base : ". $base .", altitude : ". $altitude ." ] ");
		echo("\n Parallelogram Area : ". $area ."\n\n");
	}
}

function main()
{
	$obj = new Parallelogram();
	//Test Cases  
	$obj->parallelogram_area(3.9, 8.8);
	$obj->parallelogram_area(5.1, 11.2);
	$obj->parallelogram_area(4, 10);
	$obj->parallelogram_area(1.6, 2);
}
main();

Output

 Parallelogram Size [ base : 8.8, altitude : 3.9 ]
 Parallelogram Area : 34.32

 Parallelogram Size [ base : 11.2, altitude : 5.1 ]
 Parallelogram Area : 57.12

 Parallelogram Size [ base : 10, altitude : 4 ]
 Parallelogram Area : 40

 Parallelogram Size [ base : 2, altitude : 1.6 ]
 Parallelogram Area : 3.2
/*
  Node Js program
  Find area of parallelogram
*/
class Parallelogram
{
	//Calculate area of parallelogram by given altitude and base
	parallelogram_area(altitude, base)
	{
		//Calculate area of parallelogram
		var area = base *altitude;
		//Display the result of parallelogram area
		process.stdout.write(" Parallelogram Size [ base : " + base + ", altitude : " + altitude + " ] ");
		process.stdout.write("\n Parallelogram Area : " + area + "\n\n");
	}
}

function main(args)
{
	var obj = new Parallelogram();
	//Test Cases  
	obj.parallelogram_area(3.9, 8.8);
	obj.parallelogram_area(5.1, 11.2);
	obj.parallelogram_area(4, 10);
	obj.parallelogram_area(1.6, 2);
}
main();

Output

 Parallelogram Size [ base : 8.8, altitude : 3.9 ]
 Parallelogram Area : 34.32

 Parallelogram Size [ base : 11.2, altitude : 5.1 ]
 Parallelogram Area : 57.11999999999999

 Parallelogram Size [ base : 10, altitude : 4 ]
 Parallelogram Area : 40

 Parallelogram Size [ base : 2, altitude : 1.6 ]
 Parallelogram Area : 3.2
#   Python 3 program
#   Find area of parallelogram

class Parallelogram :
	# Calculate area of parallelogram by given altitude and base
	def parallelogram_area(self, altitude, base) :
		# Calculate area of parallelogram
		area = base * altitude
		
		# Display the result of parallelogram area
		print(" Parallelogram Size [ base : ", base ,", altitude : ", altitude ," ] ", end = "")
		print("\n Parallelogram Area : ", area ,"\n\n", end = "")
	

def main() :
	obj = Parallelogram()
	# Test Cases  
	obj.parallelogram_area(3.9, 8.8)
	obj.parallelogram_area(5.1, 11.2)
	obj.parallelogram_area(4, 10)
	obj.parallelogram_area(1.6, 2)


if __name__ == "__main__": main()

Output

 Parallelogram Size [ base :  8.8 , altitude :  3.9  ]
 Parallelogram Area :  34.32

 Parallelogram Size [ base :  11.2 , altitude :  5.1  ]
 Parallelogram Area :  57.11999999999999

 Parallelogram Size [ base :  10 , altitude :  4  ]
 Parallelogram Area :  40

 Parallelogram Size [ base :  2 , altitude :  1.6  ]
 Parallelogram Area :  3.2
#   Ruby program
#   Find area of parallelogram

class Parallelogram

	# Calculate area of parallelogram by given altitude and base
	def parallelogram_area(altitude, base)
	
		# Calculate area of parallelogram
		area = base * altitude
		# Display the result of parallelogram area
		print(" Parallelogram Size { base  : ", base ,", altitude  : ", altitude ," } ")
		print("\n Parallelogram Area  :", area ,"\n\n")
	end
end
def main()

	obj = Parallelogram.new()
	# Test Cases  
	obj.parallelogram_area(3.9, 8.8)
	obj.parallelogram_area(5.1, 11.2)
	obj.parallelogram_area(4, 10)
	obj.parallelogram_area(1.6, 2)
end
main()

Output

 Parallelogram Size { base  : 8.8, altitude  : 3.9 } 
 Parallelogram Area  :34.32

 Parallelogram Size { base  : 11.2, altitude  : 5.1 } 
 Parallelogram Area  :57.11999999999999

 Parallelogram Size { base  : 10, altitude  : 4 } 
 Parallelogram Area  :40

 Parallelogram Size { base  : 2, altitude  : 1.6 } 
 Parallelogram Area  :3.2

/*
  Scala program
  Find area of parallelogram
*/
class Parallelogram
{
	//Calculate area of parallelogram by given altitude and base
	def parallelogram_area(altitude: Double, base: Double): Unit = {
		//Calculate area of parallelogram
		var area: Double = base * altitude;
		//Display the result of parallelogram area
		print(" Parallelogram Size [ base : " + base + ", altitude : " + altitude + " ] ");
		print("\n Parallelogram Area : " + area + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Parallelogram = new Parallelogram();
		//Test Cases  
		obj.parallelogram_area(3.9, 8.8);
		obj.parallelogram_area(5.1, 11.2);
		obj.parallelogram_area(4, 10);
		obj.parallelogram_area(1.6, 2);
	}
}

Output

 Parallelogram Size [ base : 8.8, altitude : 3.9 ]
 Parallelogram Area : 34.32

 Parallelogram Size [ base : 11.2, altitude : 5.1 ]
 Parallelogram Area : 57.11999999999999

 Parallelogram Size [ base : 10.0, altitude : 4.0 ]
 Parallelogram Area : 40.0

 Parallelogram Size [ base : 2.0, altitude : 1.6 ]
 Parallelogram Area : 3.2
/*
  Swift program
  Find area of parallelogram
*/
class Parallelogram
{
	//Calculate area of parallelogram by given altitude and base
	func parallelogram_area(_ altitude: Double, _ base: Double)
	{
		//Calculate area of parallelogram
		let area: Double = base * altitude;
		
		//Display the result of parallelogram area
		print(" Parallelogram Size [ base : ", base ,", altitude : ", altitude ," ] ", terminator: "");
		print("\n Parallelogram Area : ", area ,"\n\n", terminator: "");
	}
}
func main()
{
	let obj: Parallelogram = Parallelogram();
	//Test Cases  
	obj.parallelogram_area(3.9, 8.8);
	obj.parallelogram_area(5.1, 11.2);
	obj.parallelogram_area(4, 10);
	obj.parallelogram_area(1.6, 2);
}
main();

Output

 Parallelogram Size [ base :  8.8 , altitude :  3.9  ]
 Parallelogram Area :  34.32

 Parallelogram Size [ base :  11.2 , altitude :  5.1  ]
 Parallelogram Area :  57.12

 Parallelogram Size [ base :  10.0 , altitude :  4.0  ]
 Parallelogram Area :  40.0

 Parallelogram Size [ base :  2.0 , altitude :  1.6  ]
 Parallelogram Area :  3.2


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