
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Area of Triangle Given All Three Sides in Go
Steps
- Read all the three sides of the triangle and store them in three separate variables.
- Using the Heron's formula, compute the area of the triangle.
- Print the area of the triangle.
Enter first side: 15 Enter second side: 9 Enter third side: 7 Area of the triangle is: 20.69 |
Enter first side: 5 Enter second side: 6 Enter third side: 7 Area of the triangle is: 14.7 |
Explanation
- User must enter all three numbers and store them in separate variables.
- First, the value of s is found which is equal to (a+b+c)/2
- Then, the Heron's formula is applied to determine the area of the triangle formed by all three sides.
- Finally, the area of the triangle is printed.
Example
package main import ( "fmt" "math" ) func main(){ var a, b, c float64 fmt.Print("Enter first side of the triangle: ") fmt.Scanf("%f", &a) fmt.Print("Enter second side of the triangle: ") fmt.Scanf("%f", &b) fmt.Print("Enter third side of the triangle: ") fmt.Scanf("%f", &c) s:=(a+b+c)/2 area:=math.Sqrt(s * (s - a) * (s - b) * (s - c)) fmt.Printf("Area of the triangle is: %.2f", area) }
Output
Enter first side of the triangle: 15 Enter second side of the triangle: 9 Enter third side of the triangle: 7 Area of the triangle is: 20.69
Advertisements