for 循环 谁能用PHP做出来 * ** *** ****
- 提问者网友:战魂
- 2021-02-27 04:57
第一行第五列有个*
第二行第4,5列有*
一次类推
- 五星知识达人网友:摆渡翁
- 2021-02-27 05:14
for ($i = 5; $i > 0; $i--) {
for ($j = 1; $j <= 5; $j++) {
if ($j > $i-1) {
echo "*";
} else {
echo "&";
}
}
echo "<br/>";
}
- 1楼网友:拜訪者
- 2021-02-27 07:28
- 2楼网友:街头电车
- 2021-02-27 06:17
方式1:(速度较慢)
dim i as integer,j as integer
for i=1 to 100
for j=2 to i
if i%j=0 then
exit for
end if
if j>=i then
if i<> 1 then
print i
end if
end if
next j
next i
end if
方式2:(速度快)
dim i as integer,j as integer
for i=1 to 100
for j=2 to sqr(i)
if i%j=0 then
exit for
end if
if j>=i then
if i<> 1 then
print i
end if
end if
next j
next i
end if
方式3:(速度慢)
dim i as integer,j as integer
for i=1 to 99 step 2
for j=2 to i
if i%j=0 then
exit for
end if
if j>=i then
if i<> 1 then
print i
end if
end if
next j
next i
end if
方式4:(速度较快)
dim i as integer,j as integer
for i=1 to 99 step 2
for j=2 to sqr(i)
if i%j=0 then
exit for
end if
if j>=i then
if i<> 1 then
print i
end if
end if
next j
next i
end if
方式5:(速度很快)
dim i as integer,j as integer
for i=3 to 99 step 2
for j=2 to i
if i%j=0 then
exit for
end if
if j>=i then
print i
end if
next j
next i
end if
方式5:(速度更快)
dim i as integer,j as integer
for i=3 to 99 step 2
for j=2 to sqr(i)
if i%j=0 then
exit for
end if
if j>=i then
print i
end if
next j
next i
end if