TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Program to find the area of a triangle

Program to find the area of a triangle on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph etc.

<< Back to PROGRAM

Program to find the area of a triangle

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)


Solution

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

Next Topic#




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf