In the Go language, use the % remainder operator to calculate the remainder, which returns the remainder after the dividend minus the quotient multiplied by the divisor. For example, calculating the remainder of 100 divided by 7 yields 2.
Remainder calculation in Go language
In Go language, the remainder operator can be used to calculate the remainder%
. This operator returns the remainder of the dividend minus the quotient multiplied by the divisor.
Syntax:
result := dividend % divisor
Among them:
dividend
is the dividend divisor
is the divisorresult
is the remainderPractical case:
Write a program to calculate Remainder when 100 is divided by 7:
package main import "fmt" func main() { dividend := 100 divisor := 7 result := dividend % divisor fmt.Printf("100 除以 7 的余数是: %d\n", result) }
Output:
100 除以 7 的余数是: 2
In this example, the program calculates the remainder when dividend
is divided by divisor
and Store it in the result
variable. Finally, the program prints the remainder 2.
Note:
The above is the detailed content of Go language remainder calculation. For more information, please follow other related articles on the PHP Chinese website!