-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSequences.c
More file actions
53 lines (43 loc) · 899 Bytes
/
Sequences.c
File metadata and controls
53 lines (43 loc) · 899 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
42
43
44
45
46
47
48
49
50
51
52
53
// Sequences.c
//
//
// Created by Rodrigo Garcia and Jesus Dominguez on 09/09/2020.
//
#include"Sequences.h"
/**
* Returns the value of the fibonacci sequence at index n calculated sequentially
* @param
* n (long long int):
* Index of the fibonacci sequence
* @return long long int value
*/
long long int Sequences_sfibo(long long int n)
{
long long int i=0, j=1, temp;
long long int count;
for(count = 0;count < n;count++)
{
temp = i + j;
i = j;
j = temp;
}
return i;
}
/**
* Returns the value of the fibonacci sequence at index n calculated recursively
* @param
* n (long long int):
* Index of the fibonacci sequence
* @return long long int value
*/
long long int Sequences_rfibo(long long int n)
{
if(n < 2)
{
return n;
}
else
{
return Sequences_rfibo(n-2) + Sequences_rfibo(n-1);
}
}