Advertisement
Spocoman

02. Half Sum Element

Sep 20th, 2024 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.56 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 sumNumbers = 0
  13.     var maxNumber = 0
  14.  
  15.     for i := 1; i <= n; i++ {
  16.         fmt.Scanln(&number)
  17.         sumNumbers += number
  18.         if number > maxNumber {
  19.             maxNumber = number
  20.         }
  21.     }
  22.  
  23.     var result = sumNumbers - maxNumber
  24.    
  25.     if maxNumber == result {
  26.         fmt.Printf("Yes\nSum = %d\n", maxNumber)
  27.     } else {
  28.         fmt.Printf("No\nDiff = %d\n", int(math.Abs(float64(maxNumber - result))))
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement