Skip to content

Commit

Permalink
103-fibonacci.c
Browse files Browse the repository at this point in the history
  • Loading branch information
victorpreston committed Jun 20, 2023
1 parent 460e1aa commit de61fcf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Binary file added 0x02-functions_nested_loops/103-fibonacci
Binary file not shown.
31 changes: 31 additions & 0 deletions 0x02-functions_nested_loops/103-fibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>

/**
* main - finds and prints the sum of the even-valued terms
* followed by a new line
* Return: Always 0 (Success)
*/
int main(void)
{
int i;
unsigned long int j, k, next, sum;

j = 1;
k = 2;
sum = 0;

for (i = 1; i <= 33; ++i)
{
if (j < 4000000 && (j % 2) == 0)
{
sum = sum + j;
}
next = j + k;
j = k;
k = next;
}

printf("%lu\n", sum);

return (0);
}

0 comments on commit de61fcf

Please sign in to comment.