4. (D) Write a programs to print the Fibonacci series.

4. (D) Write a program to print the Fibonacci series.
Write a programs to print the Fibonacci series.

#include <stdio.h>
int main()
{
int i, n, t1 = 0, t2 = 1, nextTerm = 0;
printf("Enter the number of terms: ");
scanf("%d",&n);
// displays the first two terms which is always 0 and 1
printf("Fibonacci Series: %d, %d, ", t1, t2);
// i = 3 because the first two terms are already dislpayed
for (i=3; i <= n; ++i)
{
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
printf("%d, ",nextTerm);
}
return 0;
}
4. (D) Write a programs to print the Fibonacci series. 4. (D) Write a programs to print the Fibonacci series. Reviewed by admin on December 23, 2019 Rating: 5

No comments:

Powered by Blogger.