Advertisement
Spocoman

07. Area of Figures

Sep 16th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.78 KB | None | 0 0
  1. package main
  2. import (
  3.     "fmt"
  4.     "math"
  5. )
  6.  
  7. func main() {
  8.     var figure string
  9.     fmt.Scanln(&figure)
  10.    
  11.     var area = 0.0
  12.    
  13.     if (figure == "square") {
  14.         var side float64
  15.         fmt.Scanln(&side)
  16.         area = side * side
  17.     } else if (figure == "rectangle") {
  18.             var base, height float64
  19.             fmt.Scanln(&base)
  20.             fmt.Scanln(&height)
  21.             area = base * height
  22.     } else if (figure == "circle") {
  23.         var radius float64
  24.             fmt.Scanln(&radius)
  25.             area = math.Pi * radius * radius
  26.     } else if (figure == "triangle") {
  27.         var base, height float64
  28.             fmt.Scanln(&base)
  29.             fmt.Scanln(&height)
  30.             area = base * height / 2
  31.     }
  32.    
  33.     fmt.Println(area)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement