-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path104-fibonacci.c
63 lines (53 loc) · 873 Bytes
/
104-fibonacci.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
/**
* numLength - returns the lenth of string
* @num : operand number
* Return: number of digits
*/
int numLength(int num)
{
int length = 0;
if (!num)
{
return (1);
}
while (num)
{
num = num / 10;
length += 1;
}
return (length);
}
/**
* main - prints the first 98 fibonaci sequences
* Return: 0
*/
int main(void)
{
unsigned long f1 = 1, f2 = 2, tmp, mx = 100000000, f1o = 0, f2o = 0, tmpo = 0;
short int i = 1, initial0s;
while (i <= 98)
{
if (f1o > 0)
printf("%lu", f1o);
initial0s = numLength(mx) - 1 - numLength(f1);
while (f1o > 0 && initial0s > 0)
{
printf("%i", 0);
initial0s--;
}
printf("%lu", f1);
tmp = (f1 + f2) % mx;
tmpo = f1o + f2o + (f1 + f2) / mx;
f1 = f2;
f1o = f2o;
f2 = tmp;
f2o = tmpo;
if (i != 98)
printf(", ");
else
printf("\n");
i++;
}
return (0);
}