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

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

Nuttapong Suptawepong
 
_________*
________***
_______*****
______*******
_____*********
____***********
___*************
__***************
_*****************
*******************

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

			
		$scope_m = $i * 2;

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


		echo "<br/>";
	}
}


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

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

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

			
		$start_m = ( $number * 2 ) - 1;

		$scope_m = $i * 2;

		for ( $m = $start_m; $m > $scope_m; $m-- )
		{
			echo "*";
		}


		echo "<br/>";
	}
}


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


__________
_________*
________**
_______***
______****
_____*****
____******
___*******
__********
_*********
_*********
__********
___*******
____******
_____*****
______****
_______***
________**
_________*


function pyramid_left ( $number )
{
	for ( $i = 0; $i < $number; $i++ )
	{
		$scope_j = abs ( ( $number / 2 ) - $i );

		for ( $j = 0; $j < $scope_j; $j++ )
		{
			echo "_";
		}


		$scope_m = ( $number / 2 ) - $scope_j;

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


		echo "<br/>";
	}
}


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


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


function pyramid_right ( $number )
{
	for ( $i = 0; $i < $number; $i++ )
	{
		$scope_j = ( $number / 2 ) - abs ( ( $number / 2 ) - $i );

		for ( $j = 0; $j < $scope_j; $j++ )
		{
			echo "*";
		}

		echo "<br/>";
	}
}

0 Comment

  • Have no comment.

Comment Forum

 
 
 
Share This Topic Login with Facebook