首页 > 其他分享 >13、 简单应用题 输出所有的“水仙花数”。所谓的“水仙花数”是指一个3位数,其各位数字的立方和等于该数本身。例如,153是一个水仙花数,因为153=13+53+33

13、 简单应用题 输出所有的“水仙花数”。所谓的“水仙花数”是指一个3位数,其各位数字的立方和等于该数本身。例如,153是一个水仙花数,因为153=13+53+33

时间:2022-12-08 18:33:09浏览次数:36  
标签:10 13 int 153 printf 水仙花

 

 1 #include<stdio.h>
 2 int main ()
 3 {
 4     for ( int n = 100 ; n < 1000 ; n ++ )
 5     {
 6         int g = n % 10 ;
 7         int s = n / 10 % 10 ;
 8         int b = n / 100 ;
 9         if ( n == g * g * g + s * s * s + b * b * b )
10         {
11             printf ("% d ",n);
12         }
13     }
14     
15     printf ("\n");
16     return 0;
17 }

//输出:

 153  370  371  407 
Program ended with exit code: 0

 

标签:10,13,int,153,printf,水仙花
From: https://www.cnblogs.com/wojiushidalao/p/16966946.html

相关文章