In this program, You will learn how to check a number is Armstrong or not in R.
Example: How to check a number is Armstrong or not in R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | { 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:
1 2 3 4 | Enter a number :153 [1] "Number is Armstrong : 153" |