Go Program to find remainder without using the modulus operator


In this program, you will learn how to find the remainder without using the modulus operator in Go.


for <condition> { 
    statement
    increment/decrement
}

quotient and remainder

Example: How to find the remainder without using the modulus operator in Go

package main

import "fmt"

func main() {

	var a, b int
	fmt.Print("Enter two numbers:")
	fmt.Scan(&a, &b)
	
	for a >= b {
		a = a - b
	}

	fmt.Println("Remainder is:", a)
}

Output:

Enter two numbers:10 3
Remainder is: 1