初学php在论坛朋友的热线帮助下完成的一元二次的程序

来源:互联网 发布:app 竞品数据分析 编辑:程序博客网 时间:2024/05/17 03:14

下次一定要注意变量的大小写哦!

1.html

[code]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>一元二次方程简单处理程序 fallingleaf@mail.csdn.net</title>
</head>
<!--BY fallingleaf@mail.csdn.net -->
<body>
<p>输入的格式为a(X*X)+bX+c:</p>
<form method="post" action="math.php">
<p>a=
  <input type="text" maxlength=25 size=10 name="a"  >
  <br/>
  b=
  <input type="text" maxlength=25 size=10 name="b" >
  <br/>
  c=
  <input type="text" maxlength=25 size=10 name="c" >
  <br/>
  <input type="submit" name="submit" value="提交" >
  <br/>
</p>
</form>
<hr />
<span class="STYLE5">Copyleft &copy; <a href="http://blog.csdn.net/fallingleaf">fallingleaf</a> 2007  All rights Reserved</span></div>
</body>
</html>

[/code]

math.php

[code]

<?php
//获取数值
$first = $_POST["a"];
$second = $_POST["b"];
$third = $_POST["c"];
//计算“待而塔”
$d=$second*$second-4*$first*$third;
//程序内容
if($d>0)
 {
 $x1=(-$second+sqrt($d))/2*$first;
 $x2=(-$second-sqrt($d))/2*$first;
 echo "$x1<br>";
 echo "$x2";
 }  
 elseif($d==0)
{
 $x=(-$second+sqrt($d))/2*$first;
 echo "$x";
 }
 else
{
   echo "方程无实数根!";
 }
 ?>

[/code]

 

原创粉丝点击