Q:

Program to find the area of a triangle

belongs to collection: Basic Programs

0

Explanation

Three sided polygon is known as Triangle. It has a base and an altitude(height).

Area of Triangle = ½(b × h) where b is base and h is height.

Algorithm

  1. Define base and height
  2. Apply in the formula.
  3. Print the Area.

Complexity

O(1)

Input:

b = 5  

h = 12  

Output:

Area of Triangle = (b * h) / 2
                 = (5 * 12) / 2
                 = 30.0

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Python

b= 5  
h=12  
area = (b*h)/2  
print("Area of Triangle is :");  
print(area);  

 

Output:

Area of Triangle is:  30.0

 

C

#include<stdio.h>  
                   int main()   
                   { float b ,h, area;  
            b= 5;  
                                       h= 13;  
            area = (b*h) / 2 ;  
  
            printf("\n\n Area of Triangle is: %f",area);  
                       return (0);  
    }  

 

Output:

Area of Triangle is: 32.50000

 

JAVA

public class test  
 {  
   public static void main (String args[])  
    {          float b=4,h =13,area ;  
                         area = ( b*h) / 2 ;  
                         System.out.println("Area of Triangle is: "+area);  
    }}  

 

Output:

Area of Triangle is: 26.0

 

C#

using System;  
class main  
{   static void Main()   
    {  
      float  b = 5 ,h =23 ;  
      double area =  (b*h) / 2 ;   
      Console.WriteLine("Area of Triangle is :"+area);  
    }}  

 

Output:

Area of Triangle is: 57.5

 

PHP

<?php  
       $b = 5 ;  
       $h = 15 ;   
       $area =   ($b * $h) / 2;  
       echo("Area of Triangle is: ");  
       echo($area);  
?> 

 

Output:

Area of Triangle is: 37.5

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Program to find the area of the right angle triang... >>
<< Program to find the area of an equilateral triangl...