Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- var startNum, endNum, magicNum, counter int
- fmt.Scanln(&startNum)
- fmt.Scanln(&endNum)
- fmt.Scanln(&magicNum)
- var isMagic = false
- for i := startNum; i <= endNum; i++ {
- for j := startNum; j <= endNum; j++ {
- counter++
- if i + j == magicNum {
- fmt.Printf("Combination N:%d (%d + %d = %d)\n", counter, i, j, magicNum)
- isMagic = true
- break
- }
- }
- if isMagic == true {
- break
- }
- }
- if isMagic == false {
- fmt.Printf("%d combinations - neither equals %d\n", counter, magicNum)
- }
- }
- ИЛИ:
- package main
- import "fmt"
- func main() {
- var startNum, endNum, magicNum, counter int
- fmt.Scanln(&startNum)
- fmt.Scanln(&endNum)
- fmt.Scanln(&magicNum)
- for i := startNum; i <= endNum; i++ {
- for j := startNum; j <= endNum; j++ {
- counter++
- if i + j == magicNum {
- fmt.Printf("Combination N:%d (%d + %d = %d)\n", counter, i, j, magicNum)
- return
- }
- }
- }
- fmt.Printf("%d combinations - neither equals %d\n", counter, magicNum)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement