English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi i have never programmed in c before but i need this program to print the fibonacci sequence for the value entered. ie 6 =112358
Here is what i have

#
#
#
# u
#
set i = $argv[1]
if ($i == 0) then
return 0;
else if ($i == 1) then
return 1;
else
return fib[num - 1] + fib[num - 2];
endif
#
exit 0
#

2007-10-31 18:22:15 · 4 answers · asked by haze_51 1 in Computers & Internet Programming & Design

4 answers

Use the math libraries.

int i;
double sq_5,gold_ratio,fib;

sq_5=sqrt(5.0);
gold_ratio=(1+sq_5)/2;
i = atoi($argv[1]);
fib=floor(pow(gold_ratio,i)/sq_5+0.5);
return fib

2007-10-31 18:48:44 · answer #1 · answered by zenock 4 · 0 0

try it

int i, a, b, c;
a=1;
b=0;
c=0;
for(i=1;i<=6;i++)
{
c=a+b;
printf("%d", c)
a=b;
b=c;
}

2007-11-01 02:29:34 · answer #2 · answered by varinder s 1 · 0 0

you can go to codeguru.com and select the programming language you want the fibonocci series

2007-11-01 01:51:55 · answer #3 · answered by Anonymous · 0 0

Hi,
Use it

#include
#include

void main()
{
int a,b,c,i;

clrscr();
a=0;
b=1;
printf("%d\n",a);
printf("%d\n",b);

for(i=1;i<6;i++)
{
c=a+b;
printf("%d\n",c);
a=b;
b=c;
}
getch();
}

2007-11-01 01:32:48 · answer #4 · answered by iqbal 4 · 0 0

fedest.com, questions and answers