C Program to Print Fibonacci Series using For Loop

Write a Program to Print Fibonacci Series using For Loop

// C Program to Print Fibonacci Series using For Loop

#include <stdio.h>

int main()
{
	int n, i, f1, f2, f3;
	printf("Enter the number :--> ");
	scanf("%d", &n);

	f1 = 0;
	f2 = 1;
	printf("%d %d ", f1, f2);
	for(i = 1; i < n; i++)
        {
		f3 = f1 + f2;
		printf("%d ", f3);
		f1 = f2;
		f2 = f3;
	}
	return 0;
}

Output:

Enter the number :--> 5
0 1 1 2 3 5

≪ Previous | Next ≫