首頁  >  文章  >  後端開發  >  簡單的PHP演算法題(含擴充)

簡單的PHP演算法題(含擴充)

WBOY
WBOY原創
2016-08-08 09:21:101424瀏覽

簡單的PHP演算法題(待完善…)

只印0

  具體個數由輸入的參數n決定

  如n=5就列印000000印出一行0101010101010101010101 

  具體個數由輸入的參數n決定  如test.php?n=3印出010

  如test.php?n=3印出010

  如test.php?n=3印出010

 〜 1 0000 11111

  for if 實現

<?<span>php

</span><span>for</span> (<span>$i</span> = 0; <span>$i</span> < 10; <span>$i</span>++<span>) {
    </span><span>for</span> (<span>$j</span> = 0; <span>$j</span> <= <span>$i</span>; <span>$j</span>++<span>) {
        </span><span>if</span> (<span>$i</span> % 2 == 0<span>) {
            </span><span>echo</span> '0'<span>;
        } </span><span>else</span><span> {
            </span><span>echo</span> '1'<span>;
        }
    }
    </span><span>echo</span> '<br/>'<span>;
}

</span>?>

for&if語句實作

  for switch 實作 『

<?<span>php

</span><span>$i</span> = 0<span>;
</span><span>while</span> (<span>$i</span> < 10<span>) {
    </span><span>$j</span> = 0<span>;
    </span><span>while</span> (<span>$j</span> <= <span>$i</span><span>) {
        </span><span>switch</span> (<span>$i</span> % 2<span>) {
            </span><span>case</span> 0:
                <span>echo</span> '0'<span>;
                </span><span>break</span><span>;
            </span><span>case</span> 1:
                <span>echo</span> '1'<span>;
                </span><span>break</span><span>;
        }
        </span><span>$j</span>++<span>;
    }
    </span><span>echo</span> '<br/>'<span>;
    </span><span>$i</span>++<span>;
}

</span>?>
while&switch語句實作

實作0 01 010 0101…

實作0 01 012 0123 3210 210 10 0

做個計算器

  如test.php?a=1&b=2&operator=jia輸出3『如test.php?a=2&b=5&operator=cheng輸出10

  如test.php?a=6&b=3&operator=chu輸出2

可處理加減乘對

  水仙花數

  冒泡排序法

以上就介紹了簡單的PHP演算法問題(有擴充),包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn