Just for fun, I'm trying to write up some code that will list a finite number of the digits of pi, i.e. {3,1,4,1,5,...,#}
. I have the general pattern, but for some reason it's not being implemented properly in my For
loop.
For[n = 2, n <= 10, n++,
p = Pi;
int[x_] = IntegerPart[x];
digit = Table[0, {m, 1, 10}];
tab[[1]] = int[p];
tab[[n]] = int[10^(n - 1) (p - Sum[10^(-k) tab[[k + 1]], {k, 0, n - 2}])];
]
This generates the list
{3, 0, 0, 0, 0, 0, 0, 0, 0, 141592653}
I've tried checking the n
th term rule like this:
t1 = 3; t2 = 1; t3 = 4; t4 = 1; t5 = 5;
int[p]
int[10 (p - t1)]
int[100 (p - t1 - t2/10)]
int[1000 (p - t1 - t2/10 - t3/100)]
int[10000 (p - t1 - t2/10 - t3/100 - t4/1000)]
int[100000 (p - t1 - t2/10 - t3/100 - t4/1000 - t5/10000)]
which works, giving 3
, 1
, 4
, 1
, and 5
, as expected.
Note: I'm sure there's a much more efficient way of doing it, but I'm hardly a programmer - I'm not necessarily looking for suggestions to make it less expensive or anything, just why the heck this isn't working. -_-
RealDigits[]
. $\endgroup$n
th fractional digit ofPi
, you can simply evaluateRealDigits[Pi, 10, 1, -n][[1, 1]]
. $\endgroup$