Kotlin Program to Compute Quotient and Remainder

In this program, we will learn to code the Kotlin Program to Compute Quotient and Remainder. Let’s see How to compute Quotient and Remainder in Kotlin Programming language.

This program asks the user two enter the dividend and divisor, then it computes the quotient and remainder using simple arithmetic operators.

Let’s see the code of the Kotlin Program to Compute Quotient and Remainder.

Kotlin Program to Compute Quotient and Remainder

//Kotlin Program to Compute Quotient and Remainder
import java.util.Scanner;

fun main() {
    var sc = Scanner(System.`in`);
    println("Enter the Dividend: ");
    var dividend = sc.nextInt();
    println("Enter the Divisor: ");
    var divisor = sc.nextInt();
    
    var quotient = dividend / divisor;
    var remainder = dividend % divisor;
    
    println("Quotient is "+quotient);
    println("Remainder is "+remainder);
}

Output

Enter the Dividend: 18

Enter the Divisor: 7

Quotient is 2
Remainder is 4

How Does This Program Work ?

    var sc = Scanner(System.`in`);
    println("Enter the Dividend: ");
    var dividend = sc.nextInt();
    println("Enter the Divisor: ");
    var divisor = sc.nextInt();

In this program, first, we have taken the input of the dividend and the divisor from the user, using the Scanner Class of Java. We import the Scanner Class using import java.util.Scanner;

    var quotient = dividend / divisor;

We calculate the quotient of the two numbers using the division (/) operator. It divides one value by another and returns a quotient.

    var remainder = dividend % divisor;

Similarly, we calculate the remainder using the Modulus (%) operator. Modulus operators return remainder after division.

    println("Quotient is "+quotient);
    println("Remainder is "+remainder);

Finally, the quotient and remainder are displayed on the screen using println() function.

Conclusion

I hope after going through this post, you understand how to code Kotlin Program to Compute Quotient and Remainder.
If you have any doubt regarding the topic, feel free to contact us in the Comment Section. We will be delighted to help you.

Learn More:

Leave a Comment

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