-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path104-fibonacci.c
More file actions
41 lines (40 loc) · 833 Bytes
/
Copy path104-fibonacci.c
File metadata and controls
41 lines (40 loc) · 833 Bytes
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
#include <stdio.h>
#define LARGEST 10000000000
/**
* main - entry point
*
* Description: Find and print the first 98 fib numbers starting with 1 and 2.
*
* Numbers should be coma and space separated.
*
* Return: always 0 (success)
*/
int main(void)
{
unsigned long int fr1 = 0, bk1 = 1, fr2 = 0, bk2 = 2;
unsigned long int hold1, hold2, hold3;
int count;
printf("%lu, %lu, ", bk1, bk2);
for (count = 2; count < 98; count++)
{
if (bk1 + bk2 > LARGEST || fr2 > 0 || fr1 > 0)
{
hold1 = (bk1 + bk2) / LARGEST;
hold2 = (bk1 + bk2) % LARGEST;
hold3 = fr1 + fr2 + hold1;
fr1 = fr2, fr2 = hold3;
bk1 = bk2, bk2 = hold2;
printf("%lu%010lu", fr2, bk2);
}
else
{
hold2 = bk1 + bk2;
bk1 = bk2, bk2 = hold2;
printf("%lu", bk2);
}
if (count != 97)
printf(", ");
}
printf("\n");
return (0);
}