简单的PHP算法题(待完善…)
只打印0
具体个数由输入的参数n决定
如n=5就打印00000
根据n值打印n个0
打印一行 0101010101010101010101
具体个数由输入的参数n决定
如test.php?n=3打印010
根据n值打印010101…
实现1 00 111 0000 11111
for if 实现
<span>php </span><span>for</span> (<span>$i</span> = 0; <span>$i</span> $i++<span>) { </span><span>for</span> (<span>$j</span> = 0; <span>$j</span> $i; <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 switch 实现
while if 实现
while switch 实现
<span>php </span><span>$i</span> = 0<span>; </span><span>while</span> (<span>$i</span> ) { <span>$j</span> = 0<span>; </span><span>while</span> (<span>$j</span> $i<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>?>
实现0 01 010 0101……
实现0 01 012 0123 3210 210 10 0
做个计算器
如test.php?a=1&b=2&operator=jia输出3
如test.php?a=5&b=2&operator=jian输出3
如test.php?a=2&b=5&operator=cheng输出10
如test.php?a=6&b=3&operator=chu输出2
可处理加减乘除的四位一体计算函数
进阶:
水仙花数
冒泡排序法
以上就介绍了简单的PHP算法题(带扩充),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。