forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Areas2D.go
54 lines (39 loc) · 817 Bytes
/
Areas2D.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"math"
)
// Area of a Rectangle
func rectangle(l, b float64) float64 {
return l * b
}
// Area of a Square
func square(l float64) float64 {
return l * l
}
// Area of a Triangle
func triangle(b, h float64) float64 {
return (b * h) / 2.0
}
// Area of a Circle
func circle(r float64) float64 {
return math.Pi * math.Pow(r, 2)
}
// Area of a Parallelogram
func parallelogram(b, h float64) float64 {
return b * h
}
// Area of a Trapezium
func trapezium(a, b, h float64) float64 {
return (a + b) * h / 2.0
}
func main() {
fmt.Println(rectangle(3.0, 5.0))
fmt.Println(square(4.0))
fmt.Println(triangle(4.0, 6.0))
fmt.Println(circle(3.5))
fmt.Println(parallelogram(4.0, 7.0))
fmt.Println(trapezium(4.0, 3.5, 6.5))
}
// Time Complexity - O(1)
// Space Complexity - O(1)