R programming tutorials
Learn R with runnable lessons and library references for vectors, data frames, modeling, dates, and missing values.
R core curriculum
Getting started
Decisions and loops
Functions and data
Files and projects
Check a three-digit Armstrong number
input = 153
sum = 0
armstrongNumber = input
while(armstrongNumber > 0) {
i = armstrongNumber %% 10
armstrongNumber = floor(armstrongNumber / 10)
sum = sum + (i*i*i)
}
if(sum == input) {
print("The given number is an Armstrong number")
} else {
print("The given number is not an Armstrong number")
}
[1] "The given number is an Armstrong number"