Program
#include <stdio.h>
int main()
{
int a,b,temp,n;
printf("\nEnter the number upto which you want fibonacci sequence: ");
scanf("%d",&n);
printf("\nFibonacci Sequence upto %d:\n",n);
a=0;
b=1;
printf("\n%d, %d",a,b);
while (b <= n)
{
temp=b;
b=a+b;
a=temp;
if (b <= n) printf(", %d",b);
}
printf("\n\n");
}
Compilation, Run and Output
[sreedhar@manchu2 cprogs_work_machine]$ gcc fibonacci.c -o fibonacci
[sreedhar@manchu2 cprogs_work_machine]$ ./fibonacci
Enter the number upto which you want fibonacci sequence: 21
Fibonacci Sequence upto 21:
0, 1, 1, 2, 3, 5, 8, 13, 21
[sreedhar@manchu2 cprogs_work_machine]$
No comments:
Post a Comment