Description
Get the height and base value of the triangle as in the input from the user and calculate the area of triangle.
Area of triangle = (height*base)/2
Input
10
2
Output
10.00
C Program
#include <stdio.h>
int main()
{
float area,h,b;
printf("Enter the height and base: ");
scanf("%f %f",&h,&b);
area=(h*b)/2;
printf("%0.2f",area);
return 0;
}
C++ Program
#include <iostream>
using namespace std;
int main()
{
float area,h,b;
cout<<"Enter the height and base: ";
cin>>h>>b;
area=(h*b)/2;
printf("%0.2f",area);
return 0;
}
Java Program
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the length and breadth: ");
float height = sc.nextFloat();
float base = sc.nextFloat();
float area = (height*base)/2;
System.out.println(area);
}
}
Python
height = float(input("Enter the height of triangle: "))
base = float(input("Enter the base of traingle: "))
area = (height*base)/2
print(area)