C program for finding Fibonacci number up to N terms

//Program to Generate Fibonacci //Sequence Up to a Certain Number

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

    printf("Enter a positive integer: ");
    scanf("%d",&n);

    // displays the first two terms which is always 0 and 1
    printf("Fibonacci Series: %d, %d, ", t1, t2);

    nextTerm = t1+t2;

    while(nextTerm < n)
    {
        printf("%d, ",nextTerm);
        t1 = t2;
        t2 = nextTerm;
        nextTerm = t1+t2;
    }
   
    return 0;
}

Comments

Popular posts from this blog

C program to verify a number is positive or not using else if.

C program for making pyramid containing N rows

C program for finding factors