Table of contents
(1) What is the number of daffodils
Output the number of daffodils from 0-999
(1) What is the number of daffodils
Narcissus number: a number = the cube sum of its digits 153 = 1*1*1 + 5*5*5 + 3*3*3
(2) Calculation of digits
Take 153 as an example
百位:
a = i / 100;
十位:
b = i % 100 / 10;
个位
c = i % 10;
(3) All codes
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
int i;
int a, b, c;
for (i = 0; i <= 999; i++)
{
a = i / 100;
b = i % 100 / 10;
c = i % 10;
if (i == a * a * a + b * b * b + c * c * c)
{
printf("i =%d\n", i);
}
}
return 0;
}
(4) Effect display