Advertisement
Spocoman

08. Odd Even Sum

Sep 20th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.52 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. func main() {
  9.     var n, number int
  10.     fmt.Scanln(&n)
  11.    
  12.     var oddSum = 0
  13.     var evenSum = 0
  14.    
  15.     for i := 1; i <= n; i++ {
  16.         fmt.Scanln(&number)
  17.         if (i % 2 == 1) {
  18.             oddSum += number
  19.         } else {
  20.             evenSum += number
  21.         }
  22.     }
  23.  
  24.     if (oddSum == evenSum) {
  25.         fmt.Printf("Yes\nSum = %d\n", oddSum)
  26.     } else {
  27.         fmt.Printf("No\nDiff = %d\n", int(math.Abs(float64(oddSum - evenSum))))
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement