Armstrong Number

fun main() {
    println("Enter a Number")//1
    var sum=0//2
    var number = readLine()!!.toInt()//3
    val temp=number//4
    while (number!=0)//5
    {
        val digit = number%10//6
        sum=sum+(digit*digit*digit)//7
        number = number/10//8
    }
    if(temp==sum)//9
    {
        println("Entered Number $temp is ArmStrong")//10
    }
    else
    {
        println("Enter Number is $temp is not Arm Strong")//11
    }

}
  1. Instruct the user to Enter an Integer Number
  2. Declare and initialize sum variable with 0 value
  3. Take the user input and after converting into value assigned to number variable
  4. Assign number value to a temp variable
  5. Execute the while statement until the number is not
  6. Initialized the digit variable after calculating
  7. Calculate the value of sum (Calculate the cube of digit and add to sum)
  8. Assign the number of after calculation
  9. Check If the condition for the number is Armstrong or not
  10. Print Number is Arm strong
  11. Print Number is not Arm strong

Leave a Reply

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