Wednesday, May 20, 2020

Fibonacci series in C

  • Program :
#include <stdio.h>
int main()
{
    int i, n, t1 = 0, t2 = 1, nextTerm;
    printf("\n----------------FIBONACCI SERIES----------------"); 
    printf("\nEnter the number of terms: ");
    scanf("%d", &n);
    printf("\nFibonacci Series: ");

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

    return 0;
}




  • Output :


No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...