How to Display n terms of fibonacci series in C Program?
How to Display n terms of fibonacci series in C Program?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
#include <stdio.h>
int main()
{
int t1 = 0, t2 = 1, nxt = 0, n;
printf("Enter a positive number: ");
scanf("%d", &n);
// display the first 2 terms which is always 0 and 1
printf("Fibonacci Series: %d, %d, ", t1, t2);
nxt = t1 + t2;
while(nxt <= n)
{
printf("%d, ",nxt);
t1 = t2;
t2 = nxt;
nxt = t1 + t2;
}
return 0;
}