Advertisement
Spocoman

09. Sum of Two Numbers

Sep 25th, 2024
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.58 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var firstNum, secondNum, magicNum , combinations int
  7.     fmt.Scanln(&firstNum)
  8.     fmt.Scanln(&secondNum)
  9.     fmt.Scanln(&magicNum)
  10.    
  11.     for i := firstNum; i <= secondNum; i++ {
  12.         for j := firstNum; j <= secondNum; j++ {
  13.             combinations++
  14.             if i + j == magicNum {
  15.                 fmt.Printf("Combination N:%d (%d + %d = %d)\n", combinations, i, j, magicNum)
  16.                 return
  17.             }
  18.         }
  19.     }
  20.    
  21.     fmt.Printf("%d combinations - neither equals %d\n", combinations, magicNum)
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement