1#this is the code to find the area of a parrelogram and triangle
2#change the numbers to select what height and base your shape is
3
4b = 3 #b is base
5h = 3 #h is height (middle)
6
7
8t = 5 #this is the base of the triangle
9i = 5 #and this is the height
10p = t*i #dont touch this
11
12
13print("this is the area of the parrelogram")
14print(b * h)
15
16m = input("do you want to calculate a triangle? (space before answer)")
17
18print(m)
19
20if m == " yes":
21 print ("this is the area of the triangle that you inputed")
22 print (p/2)
23else:
24 print("ok")
1first you should know these details about the triangle(for the area) -
2hight (center)
3and the base lenght
4
5now, mutiply the height by the base and divide it by '2'
6
7//code
8var base = 5
9var height = 9
10var ans = (base * height) / 2
11console.log(ans)
1import java.util.Scanner;
2
3public class shw2point15 {
4
5 public static void main(String[] args) {
6 Scanner input = new Scanner(System.in);
7
8 System.out.println("Enter three points for a triangle:");
9
10 double x1 = input.nextDouble();
11 double y1 = input.nextDouble();
12 double x2 = input.nextDouble();
13 double y2 = input.nextDouble();
14 double x3 = input.nextDouble();
15 double y3 = input.nextDouble();
16
17
18 double s = ((x1 + y1) + (x2 + y2) + (x3 + y3)) / 2;
19 double area = Math.sqrt(s * (s - (x1 - y1)) * (s - (x2 - y2)) * (s - (x3 - y3)));
20
21
22
23 System.out.println("The area of the triangle is " + area);
24 }
25}
26