Fibonacci Sequence
In this lab, you will be implementing a program in C to generate the Fibonacci series up to a given number of terms. The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1.
Your task is to write a C program that takes an integer input n
using scanf()
, representing the number of terms in the Fibonacci series to be generated. The program should then calculate and print the Fibonacci series up to the n
th term, with each term separated by a space.
Examples
Here are two examples of the input and expected output for your program:
Example 1:
3 0 1 1
In this example, the input is 3
, which means the program should generate the first three terms of the Fibonacci series. The output is 0 1 1
, representing the first three terms of the series.
Example 2:
8 0 1 1 2 3 5 8 13
In this example, the input is 8
, indicating that the program should generate the first eight terms of the Fibonacci series. The output is 0 1 1 2 3 5 8 13
, representing the first eight terms of the series.