Fibonacci sequence in C programming

[ad_1]

Fibonacci
sequence in C programming

Fibonacci
sequence in c programming utilizing loops and recursion. You may print as many phrases
of sequence as your required. The variety of the sequence is named Fibonacci numbers
in c programming. The sequence begin as 0,1,1,2,3,5,8….,. Aside from the primary
two phrases of the sequence each different phrases is sum of earlier two phrases for
instance 5=3+2(addition of three and a pair of).

Fibonacci sequence Program instance in C 

#embrace <stdio.h>

int major()
{

 int n, first = 0, second = 1, subsequent, a; 
 printf(“Enter the variety of termsn”); 
 scanf(“%d”, &n);
 printf(“First %d phrases of Fibonacci sequence are:n”, n);
 for (a = 0; a < n; a++)
 {
 if (a <= 1) 
 subsequent = a; 
 else 
 {
 subsequent = first + second;
first = second;
second = subsequent; 

 } 
 printf(“%dn”, subsequent); 
 }
 return 0; 
}

Fibonacci series Program example in C

Fibonacci sequence Program instance in C 

Fibonacci sequence C programming program utilizing
recursion

#embrace<stdio.h>


int f(int); 

 int major()
 {
 int n, i = 0, a; 
 scanf(“%d”, &n); 
 printf(“Fibonacci sequence phrases are:n”); 
 for (a = 1; a <= n; a++) 
 {
 printf(“%dn”, f(i)); 
 i++;
 }

return 0; 
}
 int f(int n) 
n == 1) 
 return n;
 else
 return (f(n-1) + f(n-2)); 

Fibonacci series C programming program using recursions

Fibonacci sequence C programming program utilizing recursion

The recursive technique is much less environment friendly because it entails
reoeated operate name whereas calculating bigger time period of the sequence it could lead
to stack overflow. We are able to cut back the operating time of the recursive algorithm by
utilizing memorization( storing Fibonacci numbers which can be calculated in an array
and utilizing array for lookup). The Fibonacci sequence has many software in arithmetic
and Pc and software program engineering.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *