Write a program to find the area of a triangle ( Hint : area=1/2 b*h)
Answers
Answered by
5
The given code is written in Java.
import java.util.*;
public class TriangleArea{
public static void main(String x[]){
double base,height,area;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the base of the triangle: ");
base=sc.nextDouble();
System.out.print("Enter the height of the triangle: ");
height=sc.nextDouble();
sc.close();
area=1/2.0 * base * height;
System.out.print("The area of the triangle is: "+area+" sq units.");
}
}
- Accept the base and height of the triangle as input.
- Calculate area using formula.
- Display the area.
See the attachment for output.
Attachments:
Similar questions