How would I go about writing a nonrecursive Fibonacci number program in C?
It should prompt the user to enter the Nth term of the Fibonacci sequence, and output the term using some nonrecursive method.
I'm at a loss... Any help would be appreciated.
C programming help?
wat have u done yet
pllz post it and we will helllllp
Reply:in order to accomplish this you must analyze how the Fibonacci sequence work. we know that the first two number are 1 and 1.
and in order to get to next number we must add 2 preceeding digits. that will be the third number is equal to the sum of the first and 2nd number, and the forth number is equal to sum of the 2nd and 3rd number and so forth. so you will need to use a loop that will compute until the Nth digit is found. but keep in mind that we already know the first 2 digits so subtract 2 to nth to reach our target. using a for loop it look something like this:
print the first two digit here:
a= 1;
b=1;
for (x=1;x%26lt;=nth-2;x++)
now we will have compute for next digit let say it z remember the formula z will equal to sum of two digit preceeding it
so
z= a+b;
then print z;
after getting next digit we must re-assign the preceeding digits to get to next digit so:
a=b;
b=z;
our loop will now take us up to the nth digit.
petunia
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment