Fibonacci Series using while loop
/* Fibonacci Series using while loop */
// 0 1 1 2 3 5 8 13...
#include
int main()
{
int n,i,p,q,r;
clrscr();
printf("Enter a number: ");
scanf("%d",&n);
i=1;
p=0;
q=1;
while(i<=n)
{
printf("%d ",a);
r = p + q;
p = q;
q = r;
i++;
}
getch();
return 0;
}
Output:
No comments:
Post a Comment