Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- var n int
- fmt.Scanln(&n)
- var num0To10 = 0
- var num10To20 = 0
- var num20To30 = 0
- var num30To40 = 0
- var num40To50 = 0
- var invalidNum = 0
- var result = 0.0
- var number float64
- for i := 0; i < n; i++ {
- fmt.Scanln(&number)
- if number >= 0 && number < 10 {
- result += number * 0.2
- num0To10++
- } else if number >= 10 && number < 20 {
- result += number * 0.3
- num10To20++
- } else if number >= 20 && number < 30 {
- result += number * 0.4
- num20To30++
- } else if number >= 30 && number < 40 {
- result += 50
- num30To40++
- } else if number >= 40 && number <= 50 {
- result += 100
- num40To50++
- } else{
- result /= 2
- invalidNum++
- }
- }
- fmt.Printf("%.2f\n", result)
- fmt.Printf("From 0 to 9: %.2f%%\n", float64(num0To10) / float64(n) * 100.0)
- fmt.Printf("From 10 to 19: %.2f%%\n", float64(num10To20) / float64(n) * 100.0)
- fmt.Printf("From 20 to 29: %.2f%%\n", float64(num20To30) / float64(n) * 100.0)
- fmt.Printf("From 30 to 39: %.2f%%\n", float64(num30To40) / float64(n) * 100.0)
- fmt.Printf("From 40 to 50: %.2f%%\n", float64(num40To50) / float64(n) * 100.0)
- fmt.Printf("Invalid numbers: %.2f%%\n", float64(invalidNum) / float64(n * 100))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement