- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Kotlin Program to Compute Quotient and Remainder

In this article, we will understand how to compute the quotient and reminder in Kotlin. Quotient and Reminder is calculated using two simple formulae −

“Quotient = Dividend / Divisor” “Remainder = Dividend % Divisor”

Below is a demonstration of the same

Suppose our input is −

Dividend value: 50 Divisor: 3

The desired output would be −

Quotient: 16 Remainder: 2

## Algorithm

**Step 1**− Start**Step 2**− Declare four integers as myDividend , myDivisor, resultQuotient, resultRemainder**Step 3**− Define the integers**Step 4**− Use the formula to find the quotient and the reminder “Quotient = Dividend / Divisor” and “Remainder = Dividend % Divisor”**Step 5**− Display the result**Step 6**− Stop

## Example 1

In this example, we will calculate the Quotient and Remainder. First, set and initialize the values for Dividend and Divisor;

val myDividend = 50 val myDivisor = 3

Now, find the quotient and remainder using the above given formulae −

val resultQuotient = myDividend / myDivisor val resultRemainder = myDividend % myDivisor

Let us see the example to compute the quotient and reminder in Kotlin −

fun main() { val myDividend = 50 val myDivisor = 3 println("The Dividend value is defined as $myDividend and Divisor value is defined as $myDivisor ") val resultQuotient = myDividend / myDivisor val resultRemainder = myDividend % myDivisor println("The quotient is $resultQuotient") println("The remainder is $resultRemainder") }

## Output

The Dividend value is defined as 50 and Divisor value is defined as 3 The quotient is 16 The remainder is 2

## Example 2

In this example, we will compute Quotient and Remainder with a custom function −

fun main() { val myDividend = 50 val myDivisor = 3 println("The Dividend value is defined as $myDividend and Divisor value is defined as $myDivisor ") getValues(myDividend, myDivisor) } fun getValues(myDividend: Int, myDivisor: Int) { val resultQuotient = myDividend / myDivisor val resultRemainder = myDividend % myDivisor println("The quotient is $resultQuotient") println("The remainder is $resultRemainder") }

## Output

The Dividend value is defined as 50 and Divisor value is defined as 3 The quotient is 16 The remainder is 2

## Example 3

In this example, we will calculate the Quotient and Remainder of a negative number

fun main() { val myDividend = -40 val myDivisor = 7 println("The Dividend value is defined as $myDividend and Divisor value is defined as $myDivisor ") val resultQuotient = myDividend / myDivisor val resultRemainder = myDividend % myDivisor println("The quotient is $resultQuotient") println("The remainder is $resultRemainder") }

## Output

The Dividend value is defined as -40 and Divisor value is defined as 7 The quotient is -5 The remainder is -5

- Related Questions & Answers
- Java program to compute Remainder and Quotient
- C Program to Compute Quotient and Remainder?
- Java Program to Compute Quotient and Remainder
- C++ Program to Find Quotient and Remainder
- Program to find Quotient and Remainder in Java
- C++ Program for quotient and remainder of big number
- Python Program to Read Two Numbers and Print Their Quotient and Remainder
- Golang Program to Read Two Numbers and Print their Quotient and Remainder
- Return element-wise quotient and remainder simultaneously in Python Numpy
- Divide a given scalar element with masked array elements and return arrays with Quotient and Remainder in NumPy
- Divide masked array elements by a given scalar element and return arrays with Quotient and Remainder in NumPy
- remainder() in C++ program
- C# program to accept two integers and return the remainder
- 8085 Program to compute LCM
- C program to compute geometric progression
- C program to compute linear regression