Advertisement
Spocoman

01. Equal Sums Even Odd Position

Sep 24th, 2024
90
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 "fmt"
  4.  
  5. func main() {
  6.     var startNum, endNum int
  7.     fmt.Scanln(&startNum)
  8.     fmt.Scanln(&endNum)
  9.      
  10.     for i := startNum; i <= endNum; i++ {
  11.         var odd, even int
  12.         var digit = i
  13.          
  14.         for x := 0; x < 6; x++ {
  15.             if x % 2 == 0 {
  16.                 even += digit % 10
  17.             } else {
  18.                 odd += digit % 10
  19.             }
  20.             digit /= 10
  21.         }
  22.  
  23.         if odd == even {
  24.              fmt.Printf("%d ", i)
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement