// C Program to print Fibonacci Series #include<stdio.h> // header file declaration int main() // main method { int p1=0,p2=1,p3,i,num; // variable declaration printf("FIBONACCI SERIES\n"); printf("Input the number of elements:"); scanf("%d",&num); printf("\n%d %d",p1,p2); //printing 0 and 1 for(i=2;i<num;++i)//loop starts from 2 { p3=p1+p2; printf(" %d",p3); p1=p2; p2=p3; } getch(); } OUTPUT:
Comments
Post a Comment