输出0-999之间的水仙花数

今天分享个程序-输出0到999之间的水仙花数

#include
#include
#include

int main()
{
	int i,a,b,c=0;
	for (i = 100; i <= 999; i++)
	{
		a = i / 100;
		b = i / 10 % 10;
		c = i % 10;
		if (pow(a, 3) + pow(b, 3) + pow(c, 3) == i)
		{
			printf("%d\t",i);
		}
	}
	system("pause");
	return 0;
}

严格来说只有3位数才可以是水仙花数,所以应该是求100到999的水仙花数!

你可能感兴趣的:(简单程序)