Here is a simple program that prints out the first n numbers in the Fibonacci series in C:

  1. #include <stdio.h>
  2. int main() {
  3.   int n, i;
  4.   long long int t1 = 0, t2 = 1, nextTerm;

  5.   printf("Enter the number of terms: ");
  6.   scanf("%d", &n);

  7.   printf("Fibonacci Series: ");

  8.   for (i = 1; i <= n; ++i) {
  9.     printf("%lld, ", t1);
  10.     nextTerm = t1 + t2;
  11.     t1 = t2;
  12.     t2 = nextTerm;
  13.   }

  14.   return 0;
  15. }

  • This program first prompts the user to enter the number of terms in the Fibonacci series to be printed. It then uses a for loop to iterate through the terms and prints each one. The loop starts at 1, and it continues until the value of i is greater than n. 
  • On each iteration of the loop, the next term in the series is calculated as the sum of the previous two terms, and the variables t1 and t2 are updated to store the previous two terms. The first two terms of the series are initialized to 0 and 1, respectively.
  • This program uses a for loop to iterate through the first 20 terms in the Fibonacci series. The variables t1 and t2 represent the previous two terms, and the variable nextTerm represents the next term in the series. 
  • The program prints out the value of t1 and then updates the values of t1, t2, and nextTerm for the next iteration of the loop.
Here is a C program that prints the first n numbers of the Fibonacci series:

fibonacci series in c

Enter the number of terms: 12
First 12 terms of Fibonacci series are:
0
1
1
2
3
5
8
13
21
34
55
89
  • This program prompts the user to enter a positive integer n and then generates the first n terms of the Fibonacci series using a loop.  with the first two terms being 0 and 1. The series starts with 0 and 1 and looks like this: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
  • This program prompts the user to enter the number of terms in the Fibonacci series they want to generate, then uses a loop to compute and print out each term. The first two terms of the series are hard-coded as 0 and 1, and the remaining terms are computed by adding the previous two terms together.
  • To understand how this program works, you can read the following explanation:
  • The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. In this program, the first two numbers of the Fibonacci series are initialized to 0 and 1.
  • The for loop is used to iterate over the numbers of the series. The loop starts from 0 and ends at n-1. At each iteration, the next number in the series is calculated by adding the first and second numbers. The if statement is used to handle the case where the current iteration is 0 or 1, in which case the next number is simply the current iteration.
  • After the next number is calculated, the first and second numbers are updated for the next iteration. Finally, the next number is printed to the screen.
  • I hope this helps! Let me know if you have any questions.

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu