I need to find the digits of Fibonacci numbers till 1000 digits.
For example: 1 has 1 digit, 10 has 2 digits, 100 has 3 digits...
The Fibonacci sequence starts this way: 0,1,2,3,5,8,13...
I have to insert 1000 and get as result 4782.
I get 4781 inserting 524 see below. I would like to insert 1000 and get 4782. Is there any possible way to get the length of my stack? In python I could use the len function, in C it will not work :)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int s) {
int i = 1;
int k = 1;
int list[1000] = { 0, 1 };
int fibo = 0;
int s = -1;
int divide = 0;
while (i < 1500) {
i++;
fibo = list[i - 1] + list[i - 2];
if (i == 1000) {
break;
} else {
list[i] = fibo;
//printf("%d\n", list[i]);
}
}
while (s < 524) {
s++;
divide = 0;
while (list[s] != 0) {
divide = list[s] / 10;
list[s] = divide;
k++;
if(divide == 0) {
break;
}
}
}
printf("%d\n", k);
}