ฟังก์ชันที่ใช้แสดงผล Pyramid ครับ เคยทำไว้สมัยเรียนลองเอามาแบ่งปันดูครับ : PHP
 

Forum :: PHP :: ฟังก์ชันที่ใช้แสดงผล Pyramid ครับ เคยทำไว้สมัยเรียนลองเอามาแบ่งปันดูครับ

Nuttapong Suptawepong
 
*
**
***
****
*****
******
*******

function pyramid_left_bottom ( $number )
{
	for ( $i = 0; $i < $number; $i++ )
	{
		for ( $j = 0; $j < $i; $j++ )
		{
			echo "*";
		}

		echo "<br/>";
	}
}


------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------


********
*******
******
*****
****
***
**
*

function pyramid_left_top ( $number )
{
	for ( $i = 0; $i < $number; $i++ )
	{
		for ( $j = $number; $j > $i; $j-- )
		{
			echo "*";
		}

		echo "<br/>";
	}
}


------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------


********
_*******
__******
___*****
____****
_____***
______**
_______*

function pyramid_right_top ( $number )
{
	for ( $i = 0; $i < $number; $i++ )
	{
		for ( $j = 0; $j < $i; $j++ )
		{
			echo "_";
		}

		for ( $m = $number; $m > $i; $m-- )
		{
			echo "*";
		}

		echo "<br/>";
	}
}


------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------


_______*
______**
_____***
____****
___*****
__******
_*******
********

function pyramid_right_bottom ( $number )
{
	for ( $i = 0; $i < $number; $i++ )
	{
		for ( $j = $number - 1; $j > $i; $j-- )
		{
			echo "_";
		}

		for ( $m = 0; $m <= $i; $m++ )
		{
			echo "*";
		}

		echo "<br/>";
	}
}

0 Comment

  • Have no comment.

Comment Forum

 
 
 
Share This Topic Login with Facebook