0% found this document useful (0 votes)
3 views2 pages

Include

The document provides a C program that generates the Fibonacci series up to a user-defined number of terms. It initializes the first two terms and uses a for loop to calculate and print subsequent terms. An example output for 10 terms is included, demonstrating the sequence generated by the program.

Uploaded by

Archana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Include

The document provides a C program that generates the Fibonacci series up to a user-defined number of terms. It initializes the first two terms and uses a for loop to calculate and print subsequent terms. An example output for 10 terms is included, demonstrating the sequence generated by the program.

Uploaded by

Archana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

int main() {

int i, n;

// initialize first and second terms

int t1 = 0, t2 = 1;

// initialize the next term (3rd term)

int nextTerm = t1 + t2;

// get no. of terms from user

printf("Enter the number of terms: ");

scanf("%d", &n);

// print the first two terms t1 and t2

printf("Fibonacci Series: %d, %d, ", t1, t2);

// print 3rd to nth terms

for (i = 3; i <= n; ++i) {

printf("%d, ", nextTerm);

t1 = t2;

t2 = nextTerm;

nextTerm = t1 + t2;

return 0;

Run Code

Output

Enter the number of terms: 10


Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,

Let us suppose n = 10. First, we have printed the first two terms of the Fibonacci sequence before
using a for loop to print the next n terms.

Let us see how the for loop works:

i t1 t2 nextTerm

3 0 1 1

4 1 1 2

5 1 2 3

6 2 3 5

7 3 5 8

8 5 8 13

9 8 13 21

10 13 21 34

Fibonacci Sequence Up to a Certain

You might also like