Thursday, April 2, 2020

c program to display fibonacci series simple way example

C program to display fibonacci series simple way example 

#include 
int main()
{
    int i, n, t1 = 0, t2 = 1, nextTerm; // integer variables 
    printf("Enter the number of terms: "); // input from user
    scanf("%d", &n); // storing value entered from suer
    printf("Fibonacci Series: "); // It display the final result

    for (i = 1; i <= n; ++i) // using for loop 
    {
        printf("%d, ", t1);
        nextTerm = t1 + t2;
        t1 = t2;
        t2 = nextTerm;
    }

    return 0;
}
  • The fibonacci sequence is a sequence where the next term is the sum of its previous two terms. The two terms of terms of the fibonacci sequence followed o to 1.
The fibonacci sequence : 0,1,1,2,3,5,8,13,21,

Output

Enter the number of terms = 10
Fibonacci series 0,1,1,2,3,5,8,13,34,
Happy coding
Location: Pakistan

0 comments:

Post a Comment

Recent Posts