Program to generate the Fibonacci series.

29 Dec 2022 Balmiki Kumar 0 C Programming

Program to generate the Fibonacci series.

The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. In mathematical terms, the sequence is defined by the recurrence relation:

F(n) = F(n-1) + F(n-2)

where F(0) = 0 and F(1) = 1.

The first few numbers in the Fibonacci series are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

The Fibonacci series has many interesting properties and is widely used in mathematics, computer science, and other fields. It appears in many natural phenomena, such as the growth patterns of plants and the arrangement of leaves on a stem, and it is also used in algorithms for optimization, cryptography, and other applications.

The Series is as follows

0   1   1(1+0)     2(1+1)     3(1+2)    5(2+3)      8(3+5)     13(5+8)    21(8+13)     34(13+21) ...    and so on

 

Program 01: C program to generate Fibonacci Series

#include<stdio.h>
int main() {
 int i,fib[25];//array fib stores numbers of fibonacci series
 fib[0]=0;//initialized first element to 0
 fib[1]=1;//initialized second element to 1
 for(i=2;i<10;i++) //loop to generate ten elements
 {
 fib[i]=fib[i-1]+fib[i-2];//i'th element of series is equal to the sum of i-1'th element and i-2'th element.
 }
 printf("The fibonacci series is as follows \n");
 for(i=0;i<10;i++)//print all numbers in the series
 {
  printf("%d\n",fib[i]);//print all numbers in the series
 }
 return 0;
}

Explanation:

The first two elements are initialized to 0, 1 respectively. Other elements in the series are generated by looping and adding the previous two numbers. These numbers are stored in an array and ten elements of the series are printed as output.

BY: Balmiki Kumar

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.