Method One:
#include <stdio.h>
int main ()
{
int i,j,k,n;
printf (" Number of daffodils:", n);
for (n=100;n<1000;n++)
{
i=n/100;
j=n/10-i*10;
k=n%10;
if (n==i*i*i+j*j*j+k*k*k)
printf ("%d\n", N);
}
return 0;
}
Output Result:
Number of daffodils:153
370
371
50V
Press any key to continue
Method Two:
#include < stdio h >
#include <math. h >
int Main ()
{
int i,m,sum;
for (i=100;i<1000;i+ +)
{
sum = 0;
m = i;
Do
{
sum=sum+Pow (M%10,3);//pow(A, b ) refers to the power of a by a double type of
m=m/ten;
}
while (M!=0);
if (sum= =i)
printf ("%d", i);
}
printf ("\ n");
return 0;
}
Operation Result:
153 370 371 407
Press any key to continue
Method Three:
#include <stdio. h >
int Main ()
{
int I,j,k,n;
printf (" number of daffodils:", n);
for (n=100;n<1000;n+ +)
{
= /
j = (n - * /
k = - * - *
if(n==I*I*I+J*J*J+k*k*k)
printf ("%d\n", N);
}
return 0;
}
Results:
Number of daffodils:153
370
371
407
Press any key to continue
This article is from the "Rock Owl" blog, please be sure to keep this source http://10742111.blog.51cto.com/10732111/1713857
C Language: 3 ways to find out all the "daffodils" between 0~999 and output.