满意答案
*问题分析与算法设计
具有这种性质的四位数没有分布规律,可以采用穷举法,对所有四位数进行判断,从而筛选出符合这种性质的四位数。具体算法实现,可任取一个四位数,将其截为两部分,前两位为a,后两位为b,然后套用公式计算并判断。
*程序说明与注释
#include
int main()
{
int n,a,b;
printf("There are following number with 4 digits satisfied condition\n");
for(n=1000;n<10000;n++) /*四位数N的取值范围1000~9999*/
{
a=n/100; /*截取N的前两位数存于a*/
b=n%100; /*截取N的后两位存于b*/
if((a+b)*(a+b)==n) /*判断N是否为符合题目所规定的性质的四位数*/
printf("%d ",n);
}
}
*运行结果
There are following numbers with 4 digits satisfied condition:
2025 3025 9801
12分享举报