library is about to close and don't have time right now.
its really stumping me however as I went over and over this code in my mind as I actually wrote it out on paper and my gut tells me it should work.
very long get_int_size(very long n)
{//I think this is for positive ints only
very long counter = 1, divisor = 1;
while( (counter++) && (divisor *= 10) )
if ((n/divisor) >= 1)
continue;
elsebreak;
return counter-1;
}
int nth_digit(int n, int d)
{
int tn = n;
if (tn<0)
tn *= -1; //do I need this?
int s = get_int_size(tn);
if (d > s || d < 1)
return -1;
int increment = 1,place_holder = 10, counter = 0;
for (int i = 1; i < d; ++i)
{
tn = tn - (increment * nth_digit(tn, i));
place_holder *= 10;
increment *=10;
}
doif (tn % place_holder == 0)
return ((place_holder - (counter*increment)) %place_holder )/increment;
while(tn +=increment && counter++ && tn <= (n + place_holder));
return -2;
}
That looks overly complicated, a simple loop dividing your integer by 10 (n) times will do, then use modulo operator to return the remainder of that value divided by 10.