-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibC.c
More file actions
35 lines (29 loc) · 753 Bytes
/
FibC.c
File metadata and controls
35 lines (29 loc) · 753 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
/**
* C program to print Fibonacci series up to n terms
*/
#include <stdio.h>
#include <time.h>
int main()
{
clock_t tStart = clock();
int a, b, c, i, terms;
/* Input number from user */
/* printf("Enter number of terms: ");
scanf("%d", &terms); */
terms = 777 ;
/* Fibonacci magic initialization */
a = 0;
b = 1;
c = 0;
printf("Fibonacci terms: \n");
/* Iterate through n terms */
for(i=1; i<=terms; i++)
{
printf("%d, ", c);
a = b; // Copy n-1 to n-2
b = c; // Copy current to n-1
c = a + b; // New term
}
printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
return 0;
}