Find the triangle area by using sas

Calculate SAS Triangle Area

Here given code implementation process.

//C Program 
//Find the area of sas triangle
#include <stdio.h>

#include <math.h>

//Find area of triangle using given sides a, b and angle c
void sas_triangle_area(double a, double b, int c)
{
	// a and b is side
	// c is angle
	/*
	    Area of sas triangle 
	   
	          ab sin c
	        --------
	            2
	*/
	// Convert given degrees to radians
	double radians = c * (M_PI / 180.0);
	double area = (a * b * sin(radians)) / 2;
	printf(" Triangle  [ a : %lf, b : %lf c : %d ] ", a, b, c);
	printf("\n Area : %lf\n\n", area);
}
int main()
{
	//Test Cases
	sas_triangle_area(31.4, 29.3, 41);
	sas_triangle_area(17.9, 25.1, 98);
	sas_triangle_area(16.8, 33.6, 77);
	return 0;
}

Output

 Triangle  [ a : 31.400000, b : 29.300000 c : 41 ]
 Area : 301.793714

 Triangle  [ a : 17.900000, b : 25.100000 c : 98 ]
 Area : 222.458770

 Triangle  [ a : 16.800000, b : 33.600000 c : 77 ]
 Area : 275.006207
/*
  Java program
  Find the area of sas triangle
*/
class TriangleArea
{
	//Find area of triangle using given sides a, b and angle c
	public void sas_triangle_area(double a, double b, int c)
	{
		// a and b is side
	    // c is angle
	    /*
	        Area of sas triangle 
	       
	              ab sin c
	            --------
	                2
	    */
	    // Convert given degrees to radians
		double radians = c * (Math.PI / 180.0);
		
		double area = (a * b * Math.sin(radians)) / 2;

		System.out.print(" Triangle [ a : " + a + ", b : " + b + " c : " + c + " ] ");
		System.out.print("\n Area : " + area + "\n\n");
	}
	public static void main(String[] args)
	{
		TriangleArea obj = new TriangleArea();

		    obj.sas_triangle_area(31.4,29.3,41);

		    obj.sas_triangle_area(17.9,25.1,98);

		    obj.sas_triangle_area(16.8,33.6,77);
	}
}

Output

 Triangle [ a : 31.4, b : 29.3 c : 41 ]
 Area : 301.79371392592327

 Triangle [ a : 17.9, b : 25.1 c : 98 ]
 Area : 222.45877030245006

 Triangle [ a : 16.8, b : 33.6 c : 77 ]
 Area : 275.0062070849848
/*
  C++ program
  Find the area of sas triangle
*/
#include<iostream>
#include<math.h>
using namespace std;
class TriangleArea
{
	public:
		//Find area of triangle using given sides a, b and angle c
		void sas_triangle_area(double a, double b, int c)
		{
			// a and b is side
			// c is angle
			/*
				        Area of sas triangle 
				       
				              ab sin c
				            --------
				                2
				    */
			// Convert given degrees to radians
			double radians = c * (M_PI / 180.0);
			double area = (a * b * sin(radians)) / 2;
			cout << " Triangle [ a : " << a << ", b : " << b << " c : " << c << " ] ";
			cout << "\n Area : " << area << "\n\n";
		}
};
int main()
{
	TriangleArea obj = TriangleArea();
	obj.sas_triangle_area(31.4, 29.3, 41);
	obj.sas_triangle_area(17.9, 25.1, 98);
	obj.sas_triangle_area(16.8, 33.6, 77);
	return 0;
}

Output

 Triangle [ a : 31.4, b : 29.3 c : 41 ]
 Area : 301.794

 Triangle [ a : 17.9, b : 25.1 c : 98 ]
 Area : 222.459

 Triangle [ a : 16.8, b : 33.6 c : 77 ]
 Area : 275.006
/*
  C# program
  Find the area of sas triangle
*/
using System;
class TriangleArea
{
	//Find area of triangle using given sides a, b and angle c
	public void sas_triangle_area(double a, double b, int c)
	{
		// a and b is side
		// c is angle
		/*
			        Area of sas triangle 
			       
			              ab sin c
			            --------
			                2
			    */
		// Convert given degrees to radians
		double radians = c * (Math.PI / 180.0);
		double area = (a * b * Math.Sin(radians)) / 2;
		Console.Write(" Triangle [ a : " + a + ", b : " + b + " c : " + c + " ] ");
		Console.Write("\n Area : " + area + "\n\n");
	}
	public static void Main(String[] args)
	{
		TriangleArea obj = new TriangleArea();
		obj.sas_triangle_area(31.4, 29.3, 41);
		obj.sas_triangle_area(17.9, 25.1, 98);
		obj.sas_triangle_area(16.8, 33.6, 77);
	}
}

Output

 Triangle [ a : 31.4, b : 29.3 c : 41 ]
 Area : 301.793713925923

 Triangle [ a : 17.9, b : 25.1 c : 98 ]
 Area : 222.45877030245

 Triangle [ a : 16.8, b : 33.6 c : 77 ]
 Area : 275.006207084985
<?php
/*
  Php program
  Find the area of sas triangle
*/
class TriangleArea
{
	//Find area of triangle using given sides a, b and angle c
	public	function sas_triangle_area($a, $b, $c)
	{
		// a and b is side
		// c is angle
		/*
			        Area of sas triangle 
			       
			              ab sin c
			            --------
			                2
			    */
		// Convert given degrees to radians
		$radians = $c * (M_PI / 180.0);
		$area = ($a * $b * sin($radians)) / 2;
		echo " Triangle [ a : ". $a .", b : ". $b ." c : ". $c ." ] ";
		echo "\n Area : ". $area ."\n\n";
	}
}

function main()
{
	$obj = new TriangleArea();
	$obj->sas_triangle_area(31.4, 29.3, 41);
	$obj->sas_triangle_area(17.9, 25.1, 98);
	$obj->sas_triangle_area(16.8, 33.6, 77);
}
main();

Output

 Triangle [ a : 31.4, b : 29.3 c : 41 ]
 Area : 301.79371392592

 Triangle [ a : 17.9, b : 25.1 c : 98 ]
 Area : 222.45877030245

 Triangle [ a : 16.8, b : 33.6 c : 77 ]
 Area : 275.00620708498
/*
  Node Js program
  Find the area of sas triangle
*/
class TriangleArea
{
	//Find area of triangle using given sides a, b and angle c
	sas_triangle_area(a, b, c)
	{
		// a and b is side
		// c is angle
		/*
			        Area of sas triangle 
			       
			              ab sin c
			            --------
			                2
			    */
		// Convert given degrees to radians
		var radians = c * (Math.PI / 180.0);
		var area = (a * b * Math.sin(radians)) / 2;
		process.stdout.write(" Triangle [ a : " + a + ", b : " + b + " c : " + c + " ] ");
		process.stdout.write("\n Area : " + area + "\n\n");
	}
}

function main()
{
	var obj = new TriangleArea();
	obj.sas_triangle_area(31.4, 29.3, 41);
	obj.sas_triangle_area(17.9, 25.1, 98);
	obj.sas_triangle_area(16.8, 33.6, 77);
}
main();

Output

 Triangle [ a : 31.4, b : 29.3 c : 41 ]
 Area : 301.79371392592327

 Triangle [ a : 17.9, b : 25.1 c : 98 ]
 Area : 222.45877030245006

 Triangle [ a : 16.8, b : 33.6 c : 77 ]
 Area : 275.0062070849848
#   Python 3 program
#   Find the area of sas triangle
import math

class TriangleArea :
	# Find area of triangle using given sides a, b and angle c
	def sas_triangle_area(self, a, b, c) :
		#  a and b is side
		#  c is angle
		# 
		# 	        Area of sas triangle 
		# 	       
		# 	              ab sin c
		# 	            --------
		# 	                2
		# 	    
		
		#  Convert given degrees to radians
		radians = c * (math.pi / 180.0)
		area = (a * b * math.sin(radians)) / 2
		print(" Triangle [ a : ", a ,", b : ", b ," c : ", c ," ] ", end = "")
		print("\n Area : ", area ,"\n\n", end = "")
	

def main() :
	obj = TriangleArea()
	obj.sas_triangle_area(31.4, 29.3, 41)
	obj.sas_triangle_area(17.9, 25.1, 98)
	obj.sas_triangle_area(16.8, 33.6, 77)

if __name__ == "__main__": main()

Output

 Triangle [ a :  31.4 , b :  29.3  c :  41  ]
 Area :  301.79371392592327

 Triangle [ a :  17.9 , b :  25.1  c :  98  ]
 Area :  222.45877030245006

 Triangle [ a :  16.8 , b :  33.6  c :  77  ]
 Area :  275.0062070849848
#   Ruby program
#   Find the area of sas triangle

class TriangleArea

	# Find area of triangle using given sides a, b and angle c
	def sas_triangle_area(a, b, c)
	
		#  a and b is side
		#  c is angle
		# 
		# 	        Area of sas triangle 
		# 	       
		# 	              ab sin c
		# 	            --------
		# 	                2
		# 	    
		
		#  Convert given degrees to radians
		radians = c * (Math::PI / 180.0)
		area = (a * b * Math.sin(radians)) / 2
		print(" Triangle [ a : ", a ,", b : ", b ," c : ", c ," ] ")
		print("\n Area : ", area ,"\n\n")
	end
end
def main()

	obj = TriangleArea.new()
	obj.sas_triangle_area(31.4, 29.3, 41)
	obj.sas_triangle_area(17.9, 25.1, 98)
	obj.sas_triangle_area(16.8, 33.6, 77)
end
main()

Output

 Triangle [ a : 31.4, b : 29.3 c : 41 ] 
 Area : 301.79371392592327

 Triangle [ a : 17.9, b : 25.1 c : 98 ] 
 Area : 222.45877030245006

 Triangle [ a : 16.8, b : 33.6 c : 77 ] 
 Area : 275.0062070849848

/*
  Scala program
  Find the area of sas triangle
*/
class TriangleArea
{
	//Find area of triangle using given sides a, b and angle c
	def sas_triangle_area(a: Double, b: Double, c: Int): Unit = {
		// a and b is side
		// c is angle
		/*
			        Area of sas triangle 
			       
			              ab sin c
			            --------
			                2
			    */
		// Convert given degrees to radians
		var radians: Double = c * (Math.PI / 180.0);
		var area: Double = (a * b * Math.sin(radians)) / 2;
		print(" Triangle [ a : " + a + ", b : " + b + " c : " + c + " ] ");
		print("\n Area : " + area + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: TriangleArea = new TriangleArea();
		obj.sas_triangle_area(31.4, 29.3, 41);
		obj.sas_triangle_area(17.9, 25.1, 98);
		obj.sas_triangle_area(16.8, 33.6, 77);
	}
}

Output

 Triangle [ a : 31.4, b : 29.3 c : 41 ]
 Area : 301.79371392592327

 Triangle [ a : 17.9, b : 25.1 c : 98 ]
 Area : 222.45877030245006

 Triangle [ a : 16.8, b : 33.6 c : 77 ]
 Area : 275.0062070849848
/*
  Swift program
  Find the area of sas triangle
*/
import Foundation
class TriangleArea
{
	//Find area of triangle using given sides a, b and angle c
	func sas_triangle_area(_ a: Double, _ b: Double, _ c: Int)
	{
		// a and b is side
		// c is angle
		/*
			        Area of sas triangle 
			       
			              ab sin c
			            --------
			                2
			    */
		// Convert given degrees to radians
		let radians: Double = Double(c) * (Double.pi / 180);
		let area: Double = (a * b * sin(radians)) / 2;
		print(" Triangle [ a : ", a ,", b : ", b ," c : ", c ," ] ", terminator: "");
		print("\n Area : ", area ,"\n\n", terminator: "");
	}
}
func main()
{
	let obj: TriangleArea = TriangleArea();
	obj.sas_triangle_area(31.4, 29.3, 41);
	obj.sas_triangle_area(17.9, 25.1, 98);
	obj.sas_triangle_area(16.8, 33.6, 77);
}
main();

Output

 Triangle [ a :  31.4 , b :  29.3  c :  41  ]
 Area :  301.793713925923

 Triangle [ a :  17.9 , b :  25.1  c :  98  ]
 Area :  222.45877030245

 Triangle [ a :  16.8 , b :  33.6  c :  77  ]
 Area :  275.006207084985


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