C/C++ 水仙花數

#include<stdio.h> 
int main(void)
{
    int n,a,b, c;
    printf("1000以內的所有水仙花數有:\n");
    for(n=100;n<1000;n++)
      {
        a = n % 10 ;   //個位數 
        b = (n %100 ) / 10 ;//十位數 
        c = n/100; 
        if ((a*a*a+b*b*b+c*c*c)==n)
            printf("%d\n",n);
      }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章