This project is a simple C program that generates the Fibonacci sequence up to a specified number of terms. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1.
- Generates the Fibonacci sequence up to any given number of terms.
- Easy-to-use terminal interface with formatted input/output.
- Simple and fast execution for educational and practical use.
-
Input: The user is prompted to enter the number of terms for the Fibonacci sequence.
- If the input is a valid positive integer, the program will generate and display the Fibonacci sequence up to that many terms.
- If the input is invalid (e.g., negative or zero), the program will ask the user to enter a valid input.
-
Processing: The program calculates each number in the sequence using the formula:
F(n) = F(n-1) + F(n-2)
where
F(1) = 0
andF(2) = 1
. -
Output: The program outputs the Fibonacci sequence in a well-formatted way on the terminal.
First, ensure you have a C compiler installed on your machine. If not, install one:
-
Linux/Mac: Use
gcc
, usually installed by default, or install it via terminal:sudo apt install gcc # Ubuntu/Debian-based systems brew install gcc # macOS with Homebrew
-
Windows: Install MinGW or use an IDE like Code::Blocks or Visual Studio.
Clone or download this repository to your local machine:
git clone https://github.com/mdriyadkhan585/fibonacci-sequence-generator.git
cd fibonacci-sequence-generator
Use a C compiler like gcc
to compile the program:
gcc fibonacci.c -o fibonacci
Execute the compiled program:
./fibonacci
You'll see an interface like this:
====================================
Fibonacci Sequence Generator
====================================
Enter the number of terms you want to generate:
Here's an example of what the program will output when you input 6
as the number of terms:
====================================
Fibonacci Sequence Generator
====================================
Enter the number of terms you want to generate: 6
Fibonacci Sequence up to 6 terms:
0, 1, 1, 2, 3, 5
====================================
Program Ended
====================================
- Formatted Output: The Fibonacci sequence is displayed in a user-friendly format.
- Error Handling: If you enter a non-positive integer, the program will ask you to re-enter a valid value.
The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding numbers, typically starting with 0 and 1.
Yes! Simply enter the desired number of terms, and the program will calculate the sequence up to that point. However, note that larger inputs may take more time to calculate.
This program is designed to generate a fixed number of terms. If you wish to generate an infinite sequence, you would need to implement a loop without a fixed limit (though this would run forever unless stopped).
This project is licensed under the MIT License - see the LICENSE file for details.
Happy coding! 💻✨