Created
January 21, 2021 07:16
-
-
Save aldidoanta/f4d232bfebc60be22b30bc8bab332022 to your computer and use it in GitHub Desktop.
main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
var x, y, z int | |
fmt.Println("Masukkan x: ") | |
// fmt.Scan(&x) | |
x = 3 //isi nilai x | |
fmt.Println("Masukkan y: ") | |
// fmt.Scan(&y) | |
y = 5 //isi nilai y | |
fmt.Println("Masukkan z: ") | |
// fmt.Scan(&z) | |
z = 22 //isi nilai z | |
getResult(x, y, z) | |
} | |
func getResult(x, y, z int) { | |
var xMultiplier, yMultiplier int = 0, 0 | |
var found = false | |
for (z-(xMultiplier*x) > 0) && !found { | |
// Mencoba nilai xMultiplier satu demi satu, dimulai dari 1 | |
xMultiplier++ | |
// Menentukan nilai yMultiplier berdasarkan value xMultiplier saat ini | |
if (z-(xMultiplier*x))%y == 0 { | |
yMultiplier = (z - (xMultiplier * x)) / y | |
if yMultiplier > 0 { // Memastikan y memenuhi syarat bilangan asli (y > 0) | |
found = true | |
} | |
} | |
} | |
if !found { | |
fmt.Println("Tidak mungkin") | |
} else { | |
fmt.Println(xMultiplier, " kali ember 1, ", yMultiplier, " kali ember 2") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment