#include <stdio.h>
int main(){
//19. Write a program to generate first n number of Fibonacci series
int t1=0,t2=1,next=t1+t2,n,i;
printf("\tGenerate First N Number Of Fibonacci Series");
printf("\n==========================================================");
printf("\n\nEnter The Value Of N : ");
scanf("%d", &n);
printf("\n__________________________________________________________");
printf("\n\nFibonaci Series : %d %d",t1,t2);
for(i=3;i<=n;i++){
printf(" %d",next);
t1=t2;
t2=next;
next=t1+t2;
}
printf("\n__________________________________________________________\n\n");
return 0;
}
t1
, t2
, and next
are initialized to 0, 1, and their sum (i.e., 1), respectively. The program then prints the first two numbers of the series (i.e., t1 and t2). In each iteration of the loop, the program calculates the next number in the series (i.e., next) as the sum of the previous two numbers (i.e., t1 and t2), and then updates the values of t1, t2, and next accordingly. The program then prints the next number in the series to the console. The loop continues until i is less than or equal to n. Finally, the program ends by returning 0 to indicate that it has executed successfully.