For example,
package main
import "fmt"
func div(a int, b int) (int, bool) {
if a%b == 0 {
c := a % b
return c, true
} else {
c := a % b
return c, false
}
}
func main() {
fmt.Println(div(4, 2)) // should return (0, true)
fmt.Println(div(4, 3)) // should return (1, false)
}
Playground: https://play.golang.org/p/pEh55lBUFJI
Output:
0 true
1 false
Or simply,
package main
import "fmt"
func div(a int, b int) (int, bool) {
c := a % b
return c, c == 0
}
func main() {
fmt.Println(div(4, 2)) // should return (0, true)
fmt.Println(div(4, 3)) // should return (1, false)
}
Playground: https://play.golang.org/p/zIZvFMdzZqn
Output:
0 true
1 false
1
solved My program for div(4,2) should return (0, true) and div(4,3) should return (1, false) is giving error [closed]