no message
This commit is contained in:
17
Question04-while/Ex01.php
Normal file
17
Question04-while/Ex01.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
// TODO: 変数numを宣言し、2で初期化してください
|
||||
|
||||
|
||||
// TODO: 条件式に、変数numが100を超えた場合にfalseになるような条件を記述してください
|
||||
while () {
|
||||
|
||||
// TODO :変数numを2乗した数を変数numに代入してください
|
||||
|
||||
|
||||
// TODO: 変数numの値を出力してください
|
||||
|
||||
|
||||
}
|
||||
|
||||
echo "プログラムを終了します";
|
||||
47
Question04-while/Ex02.php
Normal file
47
Question04-while/Ex02.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// 通称「FizzBuzz問題」です
|
||||
// TODO: 変数indexを定義し、1で初期化してください
|
||||
|
||||
|
||||
// TODO: 変数indexが100以下である場合繰り返す条件式を記述してください
|
||||
while () {
|
||||
|
||||
// TODO: 変数indexの値が3でも5でも割り切れる数の場合は、「FizzBuzz」と出力
|
||||
|
||||
|
||||
// TODO: 変数indexの値が3で割り切れ、5で割り切れない場合は、「Fizz」と出力
|
||||
|
||||
|
||||
// TODO: 変数indexの値が5で割り切れ、3で割り切れない場合は、「Buzz」と出力
|
||||
|
||||
|
||||
// TODO: 変数indexの値が3でも5でも割り切れない場合は、変数indexの値を出力
|
||||
|
||||
|
||||
// TODO: 変数indexに1を加算した数を、変数indexに代入する
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* ---------出力結果例---------
|
||||
* 1
|
||||
* 2
|
||||
* Fizz
|
||||
* 4
|
||||
* Buzz
|
||||
* Fizz
|
||||
* 7
|
||||
* 8
|
||||
* Fizz
|
||||
* Buzz
|
||||
* 11
|
||||
* Fizz
|
||||
* 13
|
||||
* 14
|
||||
* FizzBuzz
|
||||
* 16
|
||||
* :
|
||||
* :
|
||||
*/
|
||||
|
||||
17
Question04-while/Ex03.php
Normal file
17
Question04-while/Ex03.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
$limitNumber = 10;
|
||||
$random = 0;
|
||||
|
||||
// TODO: ランダムで数値が生成され、数値が2であった場合にプログラムが終了する条件式にしてください。
|
||||
while () {
|
||||
|
||||
// ランダムで数字を生成するプログラムです。
|
||||
// 下記の命令を実行すると変数randomに、0以上、変数limitNumber未満の数字がランダムで代入されます
|
||||
$random = mt_rand(0, $limitNumber);
|
||||
|
||||
echo "ランダムで生成された数値:$random";
|
||||
}
|
||||
|
||||
echo "<br>プログラムを終了します。";
|
||||
|
||||
70
Question04-while/index.html
Normal file
70
Question04-while/index.html
Normal file
@@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>PTra04スタートページ</title>
|
||||
|
||||
<!-- Bootstrap Core CSS -->
|
||||
<link href="../common/css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
独習PHP第4章練習問題 <small>制御構文 - while文</small>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="panel-group" id="accordion">
|
||||
<!-- ================== PTra04-01 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex01.php" target="_blank">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex01</a> <small>2乗した値の表示</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra04-02 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex02.php" target="_blank">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Ex02</a> <small>FizzBuzz</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra04-03 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex03.php" target="_blank">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Ex03</a>
|
||||
<small>ランダムを引くまで繰り返し</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="../common/js/jquery-3.2.1.min.js"></script>
|
||||
|
||||
<!-- Bootstrap Core JavaScript -->
|
||||
<script src="../common/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user