Expt2. Python Program to find the area of triangle
Aim: Implement
a program to find the area of triangle
Algorithm:
1.Start
2.Read
three sides (a,b,c)
3.calculate s=(a+b+c)/2
4. calculate area=sqrt(s*(s-a)*(s-b)*(s-c))
5.print area
3.calculate s=(a+b+c)/2
4. calculate area=sqrt(s*(s-a)*(s-b)*(s-c))
5.print area
6.Stop
Program:
# Three sides of the
triangle a, b and c are provided by the user
a = float(input('Enter
first side: '))
b = float(input('Enter
second side: '))
c = float(input('Enter
third side: '))
# calculate the
semi-perimeter
s = (a + b + c) / 2
# calculate the area
area =
(s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the
triangle is %0.2f' %area)
Output:
Enter first side: 5
Enter second side: 6
Enter third side: 7
The area of the
triangle is 14.70
0 Comments:
Post a Comment