php输出正破金字塔

WBOY
Release: 2016-06-13 12:55:15
Original
1335 people have browsed it

php输出正立金字塔

php输出正立金字塔

???$a = 10;
????function zjt($a)???????????????????????????????????????????????//定义一个函数zjt()
????????{
???????????????global $a;
???????????????for($i = 1;$i ???????????????{
??????????????????????for($j = 1;$j??????????????????????{
??????????????????????????????echo" ";
???????????????????????}
???????????????????????for($k = 1;$k ??????????????????????{
???????????????????????????echo "* ";
???????????????????????}
???????????????????????echo "
";
?????????????????}
????????}
?????????zjt($a);????????????????????????????????????????????????????//调用函数zjt()




???$a = 20;
???function dzjt($a)??????????????????????????????????????????//?定义了一个dzjt()的函数

???{
???????global $a;
???????for($i = 1;$i ???????{
???????????for($j = 1;$j

???????????{
????????????????echo " ";
????????????}
????????????for($k = 1;$k ???????????{
???????????????echo "* ";
????????????}
????????????echo "
";
?????????}
????}
????dzjt($a);*/??????????????????????????????????????????????????//调用djzt( )函数





???echo '1~100的素数:';
???for($i = 2;$i ???{
?????????$a = 1;??????????????????????????????//用$a的值来表示$i是否能被其他数(除了1和本身)整除
?????????for($j = 2;$j ?????????{
??????????????if($i % $j == 0)
?????????????{
???????????????????$a = 0;???????????????????//$a=0,能被其他数整除
???????????????????break;
??????????????}
?????????}
??????????if($a == 1)???????????????????????//$a=1,表示是素数
??????????{
???????????????echo $i." " ;
???????????}
????}






???echo '1~100的素数之和:'

???$sum = 0;
???for($i = 2;$i ???????{
????????????$a = 1;
????????????for($j = 2;$j ???????????{
??????????????????if($i % $j == 0)
??????????????????{
???????????????????????$a = 0;
???????????????????????break;
??????????????????}
?????????????}
?????????if($a == 1)
?????????{
?????????????$sum = $sum + $i;
?????????}
?????}
??echo "$sum";

?http://zencart.me/archives/73?php输出正立金字塔

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template