Menu Close

Go – Program to find quotient and remainder of an integer in go

Here, we will see program to find quotient and remainder of an integer in go. Given below, you can find algorithm and program.

The quotient is the number produced by the division of two numbers. We get the quotient by using division (/) operator.

The remainder is the integer value left over after dividing one integer by another. We get remainder by using modulus (%) operator.

Input: a = 7, b = 2

remainder = 7 % 2 = 1
quotient = 7 / 2 = 3


Input: a = 11, b = 4

remainder = 11 % 4 = 3
quotient = 11 / 4 = 2

Code:

package main

import (
  "fmt"
)

func get_quotient(a, b int) int {

  return a / b

}

func get_remainder(a, b int) int {

  return a % b

}

func main() {

  rem := get_remainder(7, 2)

  quo := get_quotient(7, 2)

  fmt.Println("rem: ", rem, "quo: ", quo)


  rem = get_remainder(11, 4)

  quo = get_quotient(11, 4)

  fmt.Println("rem: ", rem, "quo: ", quo)

}

Output:

rem: 1 quo: 3

rem: 3 quo: 2

To learn more about golang. Please follow given below link.

https://techieindoor.com/go-lang/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, golang program

Leave a Reply

Your email address will not be published. Required fields are marked *