Advertisement
Spocoman

11. Odd / Even Position

Sep 21st, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.25 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. func main() {
  9.     var n int
  10.     fmt.Scanln(&n)
  11.    
  12.     var oddMin = math.MaxFloat64
  13.     var oddMax = -math.MaxFloat64
  14.     var evenMin = math.MaxFloat64
  15.     var evenMax = -math.MaxFloat64
  16.     var oddSum = 0.0
  17.     var evenSum = 0.0
  18.  
  19.     var currentNum float64
  20.    
  21.     for i := 1; i <= n; i++ {
  22.         fmt.Scanln(&currentNum)
  23.         if i % 2 == 1 {
  24.             oddSum += currentNum
  25.             if currentNum < oddMin {
  26.                 oddMin = currentNum
  27.             }
  28.             if currentNum > oddMax {
  29.                 oddMax = currentNum
  30.             }
  31.         } else {
  32.             evenSum += currentNum
  33.             if currentNum < evenMin {
  34.                 evenMin = currentNum
  35.             }
  36.             if currentNum > evenMax {
  37.                 evenMax = currentNum
  38.             }
  39.         }
  40.     }
  41.  
  42.     if n == 0 {
  43.         fmt.Println("OddSum=0.00,\nOddMin=No,\nOddMax=No,")
  44.     } else {
  45.         fmt.Printf("OddSum=%.2f,\nOddMin=%.2f,\nOddMax=%.2f,\n", oddSum, oddMin, oddMax)
  46.     }
  47.  
  48.     if n <= 1 {
  49.        fmt.Println("EvenSum=0.00,\nEvenMin=No,\nEvenMax=No")
  50.     } else {
  51.        fmt.Printf("EvenSum=%.2f,\nEvenMin=%.2f,\nEvenMax=%.2f\n", evenSum, evenMin, evenMax)
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement