Program for Armstrong number in r

后端 未结 3 1442
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-20 04:43

A Number is called Armstrong Number if the sum of the cube of each digit of that number is equals to the Number itself.

Example:

  • 153 = 1 + 5^

3条回答
  •  别那么骄傲
    2021-01-20 04:51

    (a <- rowSums(matrix(as.numeric(unlist(strsplit(as.character(100:999),''))),nrow=900,byrow=TRUE)^3))[a==100:999]
    [1] 153 370 371 407
    

提交回复
热议问题