古詩詞大全網 - 經典古詩 - (用php遞歸函數輸出)1-2+3-4+....+99-100結果。

(用php遞歸函數輸出)1-2+3-4+....+99-100結果。

public?function?test(&$count,$i){

if($i?>?100){

return?;

}

if($i%2?==?1){

$count?=?$count?-?($i+1);

test($count,$i+1);

}else{

$count?=?$count?+?($i+1);

test($count,$i+1);

}

}

//執行

$i?=?1;

$count?=?1;

test($count,$i);

var_dump($count);exit;