不好意思现在才来看答案!
广陵绝唱,暂且称之为老师吧,你的编程方法对我启发很大,转头一想才知自己
的做法这末笨,补充一下2<=q<=p<=9.我忘打了,没想到各位还是做出来了.
我把广陵老师的方法改进了一下:
思路:假设原数是x,则x满足:x/10+p*pow(10,wei)=q*x;
wei表示x是几位数;
我的代码如下:
# include<stdio.h>
# include<math.h>
# define N 999999
void main()
{
long x;
int p,q,wei;
printf("Please enter two number 2<=q<=p<=9!\n");
scanf("%d%d",&p,&q);
for(x=p;x<N;x=x+10)
{
wei=log10(x)+1;
if(x/10+p*pow(10,wei)==x*q)
{printf("The number is :%ld",x);
break;}
}
if(x>=N)
printf("NOT found!\n");
getch();
}
问题:好象逻辑没错误,但不知为什么运行不出结果望各位指教!
再有看到各位高手编的程序,我受益非浅!我还须大大加油才能赶上你们!