用C语言编写程序:for语句,求1000以内所有的水仙花数。

2024-11-18 16:27:19
推荐回答(1个)
回答1:

#include
main()

      int i=0,g,s,b,a=0;
       
      for(i=0;i<1000;i++)
      {
                     if(i>=100&&i<=999) 
                     {  
                                        b=i/100;  
                                        s=(i-b*100)/10;//除10  
                                        g=i-b*100-s*10;  
                                        a=b*b*b+s*s*s+g*g*g; 
                     } 
                      
                     if(a==i)printf("%d\n",a); 
      }
}