forked from Adebayo-S/alx-low_level_programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
104-fibonacci.c
50 lines (44 loc) · 1001 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
#include <stdio.h>
/**
* main - Prints the first 98 Fibonacci numbers, starting with
* 1 and 2, separated by a comma followed by a space.
*
* Return: Always 0.
*/
int main(void)
{
int count;
unsigned long fib1 = 0, fib2 = 1, sum;
unsigned long fib1_half1, fib1_half2, fib2_half1, fib2_half2;
unsigned long half1, half2;
for (count = 0; count < 92; count++)
{
sum = fib1 + fib2;
printf("%lu, ", sum);
fib1 = fib2;
fib2 = sum;
}
fib1_half1 = fib1 / 10000000000;
fib2_half1 = fib2 / 10000000000;
fib1_half2 = fib1 % 10000000000;
fib2_half2 = fib2 % 10000000000;
for (count = 93; count < 99; count++)
{
half1 = fib1_half1 + fib2_half1;
half2 = fib1_half2 + fib2_half2;
if (fib1_half2 + fib2_half2 > 9999999999)
{
half1 += 1;
half2 %= 10000000000;
}
printf("%lu%lu", half1, half2);
if (count != 98)
printf(", ");
fib1_half1 = fib2_half1;
fib1_half2 = fib2_half2;
fib2_half1 = half1;
fib2_half2 = half2;
}
printf("\n");
return (0);
}