R Program to check a number is Armstrong or not


In this program, You will learn how to check a number is Armstrong or not in R.


Some list of Armstrong numbers: 153, 370, 371, 407

Example: How to check a number is Armstrong or not in R

{
    n = as.integer(readline(prompt = "Enter a number :"))

    rev = 0
    num = n

    while (n > 0) {
      r = n %% 10
      rev = rev + r * r * r
      n = n %/% 10
    }

    if (rev == num)
    {
      print(paste("Number is Armstrong :", rev))
    }
    else{
      print(paste("Number is not Armstrong :", rev))
    }
}

Output:

Enter a number :153
[1] "Number is Armstrong : 153"