/*
阿姆斯壮数 

说明:
在三位的整数中,例如153可以满足1^3 + 5^3 + 3^3 = 153,这样的数称之为Armstrong数,试写出一程式找出所有的三位数Armstrong数。

解法:
Armstrong数的寻找,其实就是在问如何将一个数字分解为个位数、十位数、百位数......,这只要使用除法与余数运算就可以了,例如输入 input
为abc,则:
a = input / 100
b = (input%100) / 10
c = input % 10

*/ 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
    int a, b, c;
    int input;
    
    printf("search Armstrong numbers in 999: \n");
    
    for(input = 100; input <= 999; input++)
    {
        a = input / 100;
        b = (input % 100) / 10;
        c = input % 10;
        if(a * a * a + b * b * b + c * c * c == input)
        {
            printf("%d \n", input);
        }
    }
    
    printf("\n");
    
    return 0;
}

 

结果:

【阿姆斯壮数 】

 

相关文章:

  • 2021-12-05
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
猜你喜欢
  • 2021-11-08
  • 2022-03-03
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-05-29
相关资源
相似解决方案