Advertisement
Spocoman

03. Histogram

Sep 20th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.75 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var n, number int
  7.     fmt.Scanln(&n)
  8.  
  9.     var p1 = 0.0
  10.     var p2 = 0.0
  11.     var p3 = 0.0
  12.     var p4 = 0.0
  13.     var p5 = 0.0
  14.  
  15.     for i := 0; i < n; i++ {
  16.         fmt.Scanln(&number)
  17.         if number < 200 {
  18.             p1 += 1
  19.         } else if number < 400 {
  20.             p2 += 1
  21.         } else if number < 600 {
  22.             p3 += 1
  23.         } else if number < 800 {
  24.             p4 += 1
  25.         } else {
  26.             p5 += 1
  27.         }
  28.     }
  29.  
  30.     fmt.Printf("%.2f%%\n", p1 / float64(n) * 100)
  31.     fmt.Printf("%.2f%%\n", p2 / float64(n) * 100)
  32.     fmt.Printf("%.2f%%\n", p3 / float64(n) * 100)
  33.     fmt.Printf("%.2f%%\n", p4 / float64(n) * 100)
  34.     fmt.Printf("%.2f%%\n", p5 / float64(n) * 100)
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement