Back to questions
JuniorTheoryCommon
What does the program print?
package main
import "fmt"
func main() {
fmt.Println(7/2, -7%3)
}3 -1
- Expecting
3.5: dividing oneintby another drops the fraction, so7 / 2is3. - Expecting a non-negative remainder, as in math: in Go the remainder takes the sign of the dividend, so
-7 % 3is-1.
- How would you change the expression so that the division prints
3.5? - What does
7 % -3evaluate to, and why?