Kotlin Program to Check Armstrong Number

Kotlin Program to Check Armstrong Number: In this program, you’ll learn to check whether a given number is Armstrong number or not. You’ll learn to do this by using a while loop in Kotlin.

Kotlin Program to Check Armstrong Number

Source Code

fun main(args: Array<String>) {
    val number = 371
    var originalNumber: Int
    var remainder: Int
    var result = 0

    originalNumber = number

    while (originalNumber != 0) {
        remainder = originalNumber % 10
        result += Math.pow(remainder.toDouble(), 3.0).toInt()
        originalNumber /= 10
    }

    if (result == number)
        println("$number is an Armstrong number.")
    else
        println("$number is not an Armstrong number.")
}

Output