An irrational decimal fraction is created by concatenating the positive integers:
0.123456789101112131415161718192021...
It can be seen that the 12th digit of the fractional part is 1.
If dn represents the nth digit of the fractional part, find the value of the following expression.
d1
d10
d100
d1000
d10000
d100000
d1000000
#define N 1000000
int main()
{
clock_t ts,te;
ts=clock();
int answer = 1;
int i;
int t = 0,len,temp = 1;
char s[6];
for (i = 1; i < N; i++)
{
sprintf(s,"%d",i);
len = strlen(s);
t+=len;
if (t >= temp )
{
answer *= (s[temp-t+len-1]-'0');
temp *=10;
}
}
printf("\nanswer %d",answer);
te=clock();
printf("\ntime difference: %ds\n",(te-ts)/CLOCKS_PER_SEC);
getchar();
return 0;
}
本文介绍了一种通过程序实现的方法来查找由连续正整数组成的无限非循环小数中的特定位置的数位。该小数由所有正整数依次连接而成,文中提供了一个C语言程序示例,用于计算指定位置的数位。

945

被折叠的 条评论
为什么被折叠?



