-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfibonacci.C
More file actions
72 lines (63 loc) · 2.13 KB
/
fibonacci.C
File metadata and controls
72 lines (63 loc) · 2.13 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* @file fibonacci.C
* @brief Prints the first n Fibonacci numbers.
*
* @author Amey Thakur
* GitHub: https://github.com/Amey-Thakur
* @author Mega Satish
* GitHub: https://github.com/msatmod
* @author Hasan Rizvi
* GitHub: https://github.com/rizvihasan
*
* @project QUADTREE-VISUALIZER
* @group Phi-CS-73
* @batch 2022
* @repo https://github.com/Amey-Thakur/QUADTREE-VISUALIZER
* @date 2021
* @license MIT
*
* Developed as part of the Phi Education Training (Milestone 2) and
* BE Major-Project @ Terna Engineering College, University of Mumbai.
*
* This program generates and prints the Fibonacci sequence.
* The Fibonacci sequence is: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
* Each number is the sum of the two preceding numbers.
*
* @return int Returns 0 on successful execution.
*/
#include <conio.h> /* Console I/O library for clrscr() and getch() (DOS/Turbo C specific) */
#include <stdio.h> /* Standard I/O library for printf and scanf functions */
/**
* @brief Prints the first n Fibonacci numbers.
*
* Uses iterative approach to generate Fibonacci sequence.
* F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2)
*
* @param n The count of Fibonacci numbers to print.
*/
void fibonacci(int n) {
int a = 0, b = 1, c,
i; /* a, b: previous two numbers; c: current; i: loop counter */
printf("Fibonacci series till %d is", n);
printf("\n%d %d", a, b); /* Print first two Fibonacci numbers */
/* Generate remaining Fibonacci numbers */
for (i = 2; i < n; i++) {
c = a + b; /* Calculate next Fibonacci number */
printf(" %d", c);
a = b; /* Shift: a becomes b */
b = c; /* Shift: b becomes c */
}
}
/**
* @brief Main function - Entry point of the program.
*
* Calls fibonacci function to print first 10 Fibonacci numbers.
*/
int main() {
int n = 10; /* Number of Fibonacci numbers to generate */
clrscr(); /* Clears the console screen (Turbo C specific) */
/* Generate and print Fibonacci sequence */
fibonacci(n);
getch(); /* Wait for a key press before closing (Turbo C specific) */
return 0; /* Return 0 to indicate successful execution */
}