當前位置:編程學習大全網 - 編程軟體 - 用PHP如何編程?由用戶輸入壹元二次方程的系數,根據系數求壹元二次方程的解,將結果輸出。

用PHP如何編程?由用戶輸入壹元二次方程的系數,根據系數求壹元二次方程的解,將結果輸出。

<html>

<body>

<div><font size=4 color=blue face="黑體"><p align=center>計算壹元二次方程的解</font></div>

<div><font size=4 face="黑體" color=red><p align=center>aX*X+bX+c=0</font></div>

<form action="" method="post">

<table border="1" align="center" cellpadding="0" cellspacing="0">

<tr><td colspan="2" align="center" bgColor="#999999">表單</td></tr>

<tr><td>系數a:</td><td><input name="a" type="text"></td></tr>

<tr><td>系數b:</td><td><input name="b" type="text"></td></tr>

<tr><td>系數c:</td><td><input name="c" type="text"></td></tr>

<tr><td colspan="2" align="center">

<input type="submit" name="submit" value="提交">

<input type="reset" name="submit2" value="重置"></td></tr>

</table>

</form>

</body>

</html>

<?php

if(isset($_POST['submit']))

{

$a=$_POST['a'];

$b=$_POST['b'];

$c=$_POST['c'];

$resu2=$b*$b-4*$a*$c;

if($resu2>=0)

{

$x1=(-$b+sqrt($resu2))/(2*$a);

$x2=(-$b-sqrt($resu2))/(2*$a);

echo"<script>alert('輸入的數為:a=".$a.",b=".$b.",c=".$c.";所以方程的解為:x1=".$x1.",x2=".$x2."');</script>";

}

else

{

echo"<script>alert('方程無解!');</script>";

}

}

>

  • 上一篇:煙臺青庭小區周邊配套怎麽樣?
  • 下一篇:匯編 已知AX中存放有壹有符號數,試編程求其絕對值。
  • copyright 2024編程學習大全網