no message
This commit is contained in:
10
Question02-Calculation/Ex01.php
Normal file
10
Question02-Calculation/Ex01.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
// 20を5で割った値を出力してください
|
||||
echo 20 / 5;
|
||||
echo nl2br("\n");
|
||||
// 126を13で掛けた値を出力してください
|
||||
echo 126 * 13;
|
||||
echo nl2br("\n");
|
||||
// 97を6で割った時の余りを出力してください
|
||||
echo 97 / 6;
|
||||
10
Question02-Calculation/Ex02.php
Normal file
10
Question02-Calculation/Ex02.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$num = 10;
|
||||
print $num;
|
||||
|
||||
// 変数numの値に30を足してください
|
||||
$num += 30;
|
||||
|
||||
// 以下のプログラムで40が出力されるようにしてください
|
||||
print $num; // ※※ この行は修正しないでください
|
||||
11
Question02-Calculation/Ex03.php
Normal file
11
Question02-Calculation/Ex03.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
$num1 = 50;
|
||||
print $num1;
|
||||
|
||||
// TODO: 変数num2に140が入るようにしてください
|
||||
// 括弧と四則演算を使って計算してください....どうすれば140という数値になるか考えてみましょう
|
||||
$num2 = (20 + $num1) * 2;
|
||||
|
||||
// 以下のプログラムで140が表示されるようにしてください
|
||||
print $num2; // ※※ この行は修正しないでください
|
||||
11
Question02-Calculation/Ex04.php
Normal file
11
Question02-Calculation/Ex04.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
$d_num = 25;
|
||||
print $d_num;
|
||||
|
||||
// TODO: プログラムを修正して、変数d_numに50が入るようにしてください
|
||||
// リテラルを使わずに、変数を使って計算してください
|
||||
$d_num = $d_num + $d_num;
|
||||
|
||||
// 以下のプログラムで50が表示されるようにしてください
|
||||
print $d_num; // ※※ この行は修正しないでください
|
||||
10
Question02-Calculation/Ex05.php
Normal file
10
Question02-Calculation/Ex05.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
// 変数ageを定義して、数値58を代入してください
|
||||
$age = 58;
|
||||
|
||||
// 変数nameを定義して、文字列"山田"を代入してください
|
||||
$name = '山田';
|
||||
|
||||
// 変数age、nameを連結して、「山田さんは、58歳です」と表示してください
|
||||
echo $name . 'さんは、' . $age . '歳です';
|
||||
20
Question02-Calculation/Ex06.php
Normal file
20
Question02-Calculation/Ex06.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
$x = 10;
|
||||
$y = 50;
|
||||
|
||||
print 'x:' . $x;
|
||||
print '<br>';
|
||||
print 'y:' . $y;
|
||||
print '<br>';
|
||||
|
||||
// 変数 x, y の値をリテラルな数字を使わずに入れ替えてください
|
||||
// ※プログラムは何行書いても良いです
|
||||
$z = $x;
|
||||
$x = $y;
|
||||
$y = $z;
|
||||
|
||||
// ここから下は修正しないでください
|
||||
print 'x:' . $x; // 「x:50」が表示される
|
||||
print '<br>';
|
||||
print 'y:' . $y; // 「y:10」が表示される
|
||||
10
Question02-Calculation/Ex07.php
Normal file
10
Question02-Calculation/Ex07.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$num = 97;
|
||||
print 'num:' . $num;
|
||||
print '<br>';
|
||||
// 変数targetを宣言して、97未満の数字を代入してください
|
||||
$target = 94;
|
||||
|
||||
// 変数numを、変数targetで割った時の商と余りを表示してください
|
||||
print $num % $target;
|
||||
8
Question02-Calculation/Ex08.php
Normal file
8
Question02-Calculation/Ex08.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$num = 20;
|
||||
$calc = 5;
|
||||
$name = "鈴木";
|
||||
|
||||
// 変数num, calc, nameを連結して、「鈴木さんは、25歳になりました」と表示してください
|
||||
echo $name . 'さんは、' . $num + $calc . '歳になりました';
|
||||
15
Question02-Calculation/Ex09.php
Normal file
15
Question02-Calculation/Ex09.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
$length = 9; // 底辺
|
||||
$height = 23; // 高さ
|
||||
|
||||
// 変数quadrangle に、四角形の面積を代入してください
|
||||
$quadrangle = $length * $height;
|
||||
|
||||
// 変数quadrangle を表示してください
|
||||
echo $quadrangle;
|
||||
echo '<br>';
|
||||
// 変数triangle に、三角形の面積を代入してください
|
||||
$triangle = $length * $height / 2;
|
||||
|
||||
// 変数triangle を表示してください
|
||||
echo $triangle;
|
||||
19
Question02-Calculation/Ex10.php
Normal file
19
Question02-Calculation/Ex10.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
$moneyInHand = 1000; // 所持金
|
||||
$coffee = 120; // コーヒーの値段
|
||||
$snack = 200; // スナック菓子の値段
|
||||
|
||||
/*
|
||||
* ● 1本あたり120円(税別)の缶コーヒーを2本
|
||||
* ● 1袋あたり200円(税別)のスナック菓子を1袋
|
||||
*
|
||||
* 上記商品を購入した時の所持金を表示してください
|
||||
* ※ 消費税は、全商品の合計に8%が加算されます
|
||||
* ※ 日本円には小数点がありませんので、整数の値で出力してください
|
||||
*/
|
||||
$total = ($coffee * 2) + $snack;
|
||||
$tax = $total * 0.08;
|
||||
$taxTruncation = floor($tax);
|
||||
$moneyInHand = $moneyInHand - ($total + $taxTruncation);
|
||||
echo '所持金' . $moneyInHand;
|
||||
151
Question02-Calculation/index.html
Normal file
151
Question02-Calculation/index.html
Normal file
@@ -0,0 +1,151 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>PTra02スタートページ</title>
|
||||
|
||||
<!-- Bootstrap Core CSS -->
|
||||
<link href="../common/css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
独習PHP第3章練習問題 <small>式と演算</small>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="panel-group" id="accordion">
|
||||
<!-- ================== PTra02-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>四則演算</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra02-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>変数と計算</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra02-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>
|
||||
|
||||
<!-- ================== PTra02-04 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex04.php" target="_blank"> <span class="glyphicon glyphicon-pencil"
|
||||
aria-hidden="true"></span>
|
||||
Ex04
|
||||
</a> <small>計算結果</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra02-05 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex05.php" target="_blank"> <span class="glyphicon glyphicon-pencil"
|
||||
aria-hidden="true"></span>
|
||||
Ex05
|
||||
</a> <small>加算と連結</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- ================== PTra02-06 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex06.php" target="_blank"> <span class="glyphicon glyphicon-pencil"
|
||||
aria-hidden="true"></span>
|
||||
Ex06
|
||||
</a> <small>スワップ</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra02-07 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex07.php" target="_blank"> <span class="glyphicon glyphicon-pencil"
|
||||
aria-hidden="true"></span>
|
||||
Ex07
|
||||
</a> <small>剰余演算</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra02-08 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex08.php" target="_blank"> <span class="glyphicon glyphicon-pencil"
|
||||
aria-hidden="true"></span>
|
||||
Ex08
|
||||
</a> <small>連結</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra02-09 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex09.php" target="_blank"> <span class="glyphicon glyphicon-pencil"
|
||||
aria-hidden="true"></span>
|
||||
Ex09
|
||||
</a> <small>面積算出</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra02-10 ================== -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a href="Ex10.php" target="_blank"> <span class="glyphicon glyphicon-pencil"
|
||||
aria-hidden="true"></span>
|
||||
Ex10
|
||||
</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"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user