Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@ta-k

# forループの練習問題（数字でピラミッドを作る）　 初級〜中級・解答編

More than 3 years have passed since last update.

# 問題

http://qiita.com/takuya-kodama/items/32edabf2c27c4b4690a0

# 解答

example.php
``````<?php

#問題１
for(\$x = 2 ; \$x >= 0 ; \$x -- ){
for(\$y = 3 ; \$y >= \$x+1 ; \$y --){
echo \$y-\$x;
}
echo "<br>";
}

#問題２
for(\$a = 1 ; \$a <= 4  ; \$a ++){
for(\$b = 3 ; \$b >= \$a ; \$b --){
echo "*";
}
for(\$c = 1 ; \$c <=\$a ; \$c++){
echo \$c;
}
for(\$d = 3 ; \$d >=6-\$c ; \$d--){
echo \$d-(4-\$a);
}
echo "<br />";
}

#問題3
\$z = 1;
for(\$x = 1 ; \$x <= 3 ; \$x ++){
for(\$y = 1 ; \$y <= 3 ; \$y ++){
echo \$z;
\$z ++;
}
echo "<br />";
}

#問題4
\$z = 1;
for(\$x = 1 ; \$x <= 3 ; \$x ++){
for(\$y = 1 ; \$y <= \$x ; \$y ++){
echo \$z;
\$z ++;
}
echo "<br />";
}

#問題5
\$z = 9;
for(\$x = 1 ; \$x <= 3 ; \$x ++){
for(\$y = 1 ; \$y <= 3 ; \$y ++){
echo \$z;
\$z --;
}
echo "<br />";
}

#問題6
\$z = 6;
for(\$x = 1 ; \$x <= 3 ; \$x ++){
for(\$y = 1 ; \$y <= \$x ; \$y ++){
echo \$z;
\$z --;
}
echo "<br />";
}

#問題7
for(\$x = 1 ; \$x <= 3 ; \$x++){
for(\$y = 1 ; \$y <= \$x ; \$y++){
echo \$y;
}
echo "<br />";
}

#問題8
for(\$x = 3 ; \$x >= 1 ; \$x--){
for(\$y = 1 ; \$y <= \$x ; \$y++){
echo \$y;
}
echo "<br />";
}

#問題9
for(\$x = 1 ; \$x <= 3 ; \$x++){
for(\$y = 3 ; \$y >= \$x ; \$y--){
echo \$y;
}
echo "<br />";
}

#問題10
for(\$x = 3 ; \$x >= 1 ; \$x--){
for(\$y = 3 ; \$y >= \$x ; \$y--){
echo \$y;
}
echo "<br />";
}

#問題11
for(\$x = 1 ; \$x <= 3 ; \$x++){
echo \$x;
for(\$y = 1 ; \$y <= 2 ; \$y ++){
echo \$y;
}
echo "<br />";
}

?>

``````
1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away