algoritma segi tiga pascal

Apr 15th, 2010 | Posted by

mumpung masih hangat, berikut ini salah satu contoh algoritma segitiga pascal beserta contoh codingnya di php

flowchart :

contoh program :

$limit	= 6;
$pascal	= "";
for($i=1;$i<=$limit;$i++){
	for($j=1;<=$i;$j++){
		if($j==1 || $j==$i){
			$value[$i][$j] = 1;
		}else{
			$value[$i][$j] = $value[$i-1][$j] + $value[$i-1][$j-1];
		}
		$pascal .= $value[$i][$j]." ";
	}
	$pascal .= "
\n";
}
echo $pascal;

output :

Related posts:

  1. constructor on scala
  2. single stack
  3. circular queue
  4. double stack
  1. akangaziz
    Apr 15th, 2010 at 20:56
    Reply | Quote | #1

    mantaff..

  2. maya
    Mar 8th, 2011 at 21:48
    Reply | Quote | #2

    mw nanya nich…..

    aq coba buat coretan dengan rumus [$i-1][$j]+[$i-1][$j-1]
    misalnya untuk i=3 dan j=2 maka rumus yang aq tulis diatas di jalankan……tapi yg aq ga ngerti hasilnya ko bisa 2….
    bukan nya [3-1][2]+[3-1][2-1]=6 ……..tolong penjelasannya ya

*