C language daffodil number

topic description

Spring is the season of flowers, and narcissus is the most charming representative among them. There is a narcissus number in mathematics, which he defines as follows: "Daffodil number" refers to a three-digit number whose cube sum is equal to its itself, for example: 153 = 1^3 + 5^3+ 3^3. Now it is required to output the number of all daffodils in the range of m and n.

Input description
There are multiple groups of input data, each group occupies one line, including two integers m and n (100 ≤ m ≤ n ≤ 999)

output description

For each test instance, it is required to output all the numbers of daffodils within a given range, that is, the number of output daffodils must be greater than or equal to m and less than or equal to n. If there are more than one, it is required to arrange them in a row from small to large output within the given range, separated by a space;
if there is no number of daffodils in the given range, then output no;
the output of each test instance occupies one line.

Example one:

enter

100 120
300 380

output

no
370 371

Code

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

int main()
{
    
    
   int m,n ,a,b,c,i,t,sum=0;
   while(scanf("%d %d",&m,&n)!=EOF)
{
    
         
      for(i=m;i<=n;i++)//i为水仙花数的循环数
      {
    
    
          t=i;
          sum=0;
          a=t%10;
          t=t/10;
          b=t%10;
          c=t/10;
          sum=a*a*a+b*b*b+c*c*c;
          if(sum==i)
          {
    
    
          count++;
          printf("%d ",i);
          }
       }
       if(count==0)
       printf("no");
       printf("\n");
   }
   return 0;
 }


**心得体会**
要注意每位数的取值方式,还有花括号是否完整,运用循环结构。

Guess you like

Origin blog.csdn.net/qq_45887317/article/details/103148076