Fibonacci series : 1 10 2 9 3 8 4 7 5 6

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pratikjajal
Forum Newbie
Posts: 4
Joined: Tue Nov 05, 2013 10:08 pm

Fibonacci series : 1 10 2 9 3 8 4 7 5 6

Post by pratikjajal »

Hello,

Herebelow, I have mentioned the code of Fibonacci series : 1 10 2 9 3 8 4 7 5 6:

Code: Select all

$j=11;
for($i=1;$i<=5;$i++)
{
	$j--;
	if($j<=6)
	{
	}
	echo "$i $j ";
}
Can we perform the same program with other loops? If yes, then describe.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Fibonacci series : 1 10 2 9 3 8 4 7 5 6

Post by requinix »

Sure. for, foreach, while, do/while... They're all mostly interchangeable. They all have an initialization phase (set up variables), a conditional phase (whether to continue executing), and an advancement phase (what to do before the next loop starts). The series you're printing out can be done any one of a billion ways.

But that's not the Fibonacci series.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Fibonacci series : 1 10 2 9 3 8 4 7 5 6

Post by Christopher »

Code: Select all

	if($j<=6)
	{
	}
:drunk:
(#10850)
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Fibonacci series : 1 10 2 9 3 8 4 7 5 6

Post by Eric! »

Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... :drunk:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Fibonacci series : 1 10 2 9 3 8 4 7 5 6

Post by requinix »

Party!

:drunk:
Prayag
Forum Newbie
Posts: 1
Joined: Sat Jun 18, 2016 8:41 am

Re: Fibonacci series : 1 10 2 9 3 8 4 7 5 6

Post by Prayag »

Can we do this question with only one varible
Post Reply