Description
This program prints the febonacci series upto the given limit. A febonacci series is generated by successively adding the last two numbers in a series. This program checks the condition that the value for n is greater than 1. Then the program uses while loop to print the febonacci series.Example
Febonacci series with linit 7, starting with 0
0, 1, 1, 2, 3, 5, 8
Program
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int f1=0,f2=1,f3,i=1,n;
printf("Enter the value of n");
l:
scanf("%d",&n);
if(n<2)
{
printf("n should be greater than 1\n");
goto l;
}
else
{
printf("\n %d\n%d",f1,f2);
while((i<=(n-2))
{
f3=f1+f2;
printf("\n %d",f3);
f1=f2;
f2=f3;
i++;
}}
getch();
}
No comments:
Post a Comment