关于自然数的一题


求助一题

自然数n的首位数字为6。若将首位数字移到个位(其它数字移到6的左侧)构成一个新数m,则n=4m。编写程序查找自然数n的最小值。
输出格式:自然数n的最小值是615384
求用简单的c语言。目前只学过数组和一点点指针。。。



2016-06-02 13:19


2016-06-02 13:22
程序代码:#include<stdio.h>
#include<math.h>
int main()
{
const unsigned base = 6;
unsigned i = 0;
unsigned tech,j;
while(1) {
tech = 0;
j = i;
while(j) {
++tech;
j/=10;
}
if((i*10+base)*4 == base*pow(10,tech)+i)
break;
i++;
}
printf("found answerd:%u\n",(i*10+base)*4);
}

2016-06-02 14:01
程序代码:#include <stdio.h>
// 由 d + x = 4 * (x*10+6),其中 d=60,600,6000,……
// 推导出 x = (d-24)/39
int main( void )
{
unsigned d;
for( d=60; (d-24)%39; d*=10 );
printf( "%u\n", d+(d-24)/39 );
return 0;
}
2016-06-02 14:33
2016-06-02 15:17
[此贴子已经被作者于2016-6-5 12:55编辑过]
2016-06-05 12:50