Home » Kotlin » Kotlin programs » Kotlin basic programs

Kotlin program to perform arithmetic operations on two numbers

Kotlin | Arithmetic operations: Here, we are going to learn how to perform various arithmetic operations on two numbers in Kotlin?
Submitted by IncludeHelp, on April 15, 2020

Here, we are implementing a Kotlin program to perform various arithmetic operations on two numbers.

Given two numbers a and b, we have to find addition, subtraction, multiplication, division, and remainder.

Example:

    Input:
    a = 13
    b = 5

    Output:
    a + b = 18
    a - b = 8
    a * b = 65
    a / b = 2
    a % b = 3

Program to perform arithmetic operations in Kotlin

package com.includehelp.basic

// Main Method Entry Point of Program
fun main(args:Array<String>){
    val a = 13
    val b = 5

    val sum  = a + b  // Perform Addition
    val sub  = a - b  // Perform Subtraction
    val muti = a * b  // Perform Multiplication
    val div  = a / b  // Perform Division
    val rem  = a % b  // Perform remainder

    // Print  on Console
    println("Addison of $a and $b is       : $sum")
    println("Subtraction of $a and $b is   : $sub")
    println("Multiplication of $a and $b is: $muti")
    println("Division of $a and $b is      : $div")
    println("Remainder of $a and $b is     : $rem")
}

Output

Addison of 13 and 5 is       : 18
Subtraction of 13 and 5 is   : 8
Multiplication of 13 and 5 is: 65
Division of 13 and 5 is      : 2
Remainder of 13 and 5 is     : 3




Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.