PHP , Sum Of Common Division 2 Numbers -
i want sum of common division between 2 number, in below code , , output maghsom moshtarak is=24612 goal 12 only; please me,
<?php $m=0; $j=6; $h=12; function sumcommon($j,$h) { echo"maghsom moshtarak is="; for($i=1;$i<=$h;$i++) { if(($j%$i==0)&&($h%$i==0)) { sum($i); } } } function sum($i) { $i+=$i; $m=$i; echo $m; } sumcommon($j,$h); ?>
<?php $m=0; $j=6; $h=12; function sumcommon($j,$h) { echo "maghsom moshtarak is="; for($i=1;$i<=$h;$i++) { if(($i%$j==0)&&($i%$h==0)) /* changed */ { sum($i); } } } function sum($i) { /* no need use $i+=$i */ $m=$i; echo $m; } sumcommon($j,$h); ?>
** refined code **
<?php $j=6; $h=12; function sumcommon($j,$h) { echo "maghsom moshtarak is="; for($i=1;$i<=$h;$i++) { if(($i%$j==0)&&($i%$h==0)) /* changed */ { echo $i; } } } sumcommon($j,$h); ?>
Comments
Post a Comment