如何以1至1000的Armstrong编号编写程序 [英] how to write a program in Armstrong number in 1 to 1000
本文介绍了如何以1至1000的Armstrong编号编写程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以1到1000的Armstrong编号编写程序.
how to write a program in Armstrong number in 1 to 1000.
推荐答案
如果您的意思是如何编写用于查找Armstrong的C程序'的数字在{1,2,.. 1000}范围内?" ,那么我建议您使用蛮力方法:对这种间隔的每个数字进行迭代,并检查它们是否满足
If you mean "how to write a C program for finding Armstrong''s numbers in the range {1,2,..1000}?" then I suggest you a brute force approach: iterate on every number of such interval and check if they satisfy the requirement.
快速搜索得出以下结果: armstrong number c程序 [ ^ ].
您可以使用它编写程序来检查范围内的所有数字.
希望对您有帮助.
A quick search yielded this result: armstrong number c program[^].
You can use it to write a program to check all the numbers in the range.
Hope it helps.
在这里,我从解决方案2的链接中修改了程序,它将告诉您从0到1000的所有armstrong编号.
here i have modified the program from Solution 2''s link, it will tell you all the armstrong number from 0 to 1000
#include <stdio.h>
main()
{
int number, sum = 0, temp, remainder;
for( number=0; number<=1000; number++)
{
temp = number;
sum=0;
while( temp != 0 )
{
remainder = temp%10;
sum = sum + remainder*remainder*remainder;
temp = temp/10;
}
if ( number == sum )
printf("%d is an armstrong number.\n", number);
}
return 0;
}
这篇关于如何以1至1000的Armstrong编号编写程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文