Skip to content
doubtly

1 answer

Best answer

#include <stdio.h>
#include <conio.h>
 
int main(){
    int terms, lastNumber=1,secondLast=0,currentNumber=0,counter;
    printf("Enter number of terms in Fibonacci series: ");
    scanf("%d", &terms);
   for(counter = 0; counter < terms; counter++){
        if(counter < 2){
            currentNumber = counter;
        } else {
            currentNumber = lastNumber + secondLast;
            secondLast = lastNumber;
            lastNumber = currentNumber;
        }
        printf("%d ", currentNumber);
    }
    getch();
    return 0;
}
Doubtly · 20 Jul 2022 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.