C Program to Print Fibonacci Series using While loop
Write C Program to Print Fibonacci Series using While loop
//WAP to print Fibonacci series #include <stdio.h> int main() { int n, i, f1, f2, f3; printf("Enter the number :--> "); scanf("%d", &n); i = 1; f1 = 0; f2 = 1; printf("%d %d ", f1, f2); while(i < n) { f3 = f1 + f2; printf("%d ", f3); f1 = f2; f2 = f3; i++; } return 0; }
Output:
Enter the number :--> 5
0 1 1 2 3 5