How to Display n terms of fibonacci series in C Program?

How to Display n terms of fibonacci series in C Program?

Senior Developer Asked on February 11, 2017 in C.
Add Comment
1 Answer(s)

#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;

}

Enter a positive integer: 100
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
Team Leader Answered on February 24, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.