使用html和php计算圆

发布于 2024-11-08 11:47:36 字数 1125 浏览 0 评论 0原文

提前致谢!

只是想问如何使用 html 和 php 计算圆的周长和面积

我的代码是这样的

<html>
<head><title>Practise</title></head> 
<body> 
<form method=post>
Circumference of a Circle or the Area <br>
The Radius of the circle: <input type="text" name="num1"><br>
<input type="submit" value="Submit"></form><hr>

<?php

   $num=$_POST["3.14"]*$_POST["num1"];
   echo "The Circuference of the circle is $num<br>"; 


?>

<hr>
</body>
</html>

编辑:

感谢您的答案!所以我这样做了,但当我尝试在 Internet Explorer 上查看 php 时,我看不到它。

这是我所做的代码:

Circumference of a Circle or the Area: <br>
The Radius of the circle: <input type="text" name="radius"> <br>
<input type="submit" value="Submit"> <hr>

<?php
    $rad = (float) $_POST['radius']; 
    $cir = $rad * 2 * pi();
    $area = pow($rad, 2) * pi();

    echo "The circumference of the circle is:" $cir.; 
    echo "The area of the circle is:" $area.;  
?>

它似乎仍然不起作用,我错过了什么?

Thanks in advance!

Just want to ask how to calculate the circumference and the area of a circle using html and php

my code is something like this

<html>
<head><title>Practise</title></head> 
<body> 
<form method=post>
Circumference of a Circle or the Area <br>
The Radius of the circle: <input type="text" name="num1"><br>
<input type="submit" value="Submit"></form><hr>

<?php

   $num=$_POST["3.14"]*$_POST["num1"];
   echo "The Circuference of the circle is $num<br>"; 


?>

<hr>
</body>
</html>

EDIT:

Thanks for the answers!!! so I did this but I can't see the php one when I tried to view it on Internet Explorer.

This is the code I did:

Circumference of a Circle or the Area: <br>
The Radius of the circle: <input type="text" name="radius"> <br>
<input type="submit" value="Submit"> <hr>

<?php
    $rad = (float) $_POST['radius']; 
    $cir = $rad * 2 * pi();
    $area = pow($rad, 2) * pi();

    echo "The circumference of the circle is:" $cir.; 
    echo "The area of the circle is:" $area.;  
?>

It still doesn't seem to work though, what am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

千紇 2024-11-15 11:47:37

我认为应该是 应该

$num= 2*$_POST['Pi']*$_POST['num1'];

echo 'the circumference -> '.$num

有效,因为帖子正在获取变量 3.14 不会像你的帖子那样工作。正如我所期望的那样,num1 是半径,如果 num1 还不是直径(2r),则周长计算需要 2 的倍数。

I think it should have been

$num= 2*$_POST['Pi']*$_POST['num1'];

echo 'the circumference -> '.$num

That should work, since post is getting variable 3.14 won't work as your post. num1 as I expect is radius and multiple of 2 is required for circumference calculation for the case if num1 is not already diameter(2r).

寄与心 2024-11-15 11:47:36

pi 已经是 PHP 中的常量,因此无需指定 $pi

代码可以简化为:

<html>
<head>
    <title>form1</title>
</head>
<body>
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Enter the radius: <input type=text name='radius'>
    <input type=submit value="submit" >
</form>
<?php


    if(!empty ($_POST['radius'])) {

        $area = pi()* $_POST{'radius'} *$_POST{'radius'};
        $perimeter = 2 * pi() * $_POST{'radius'};
        echo "perimeter = {$perimeter}\n";
        echo "Area = {$area}";
        }?>

</body>
</html>

pi is already a constant in PHP so there is no need to specify $pi

the code can be reduced to this:

<html>
<head>
    <title>form1</title>
</head>
<body>
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Enter the radius: <input type=text name='radius'>
    <input type=submit value="submit" >
</form>
<?php


    if(!empty ($_POST['radius'])) {

        $area = pi()* $_POST{'radius'} *$_POST{'radius'};
        $perimeter = 2 * pi() * $_POST{'radius'};
        echo "perimeter = {$perimeter}\n";
        echo "Area = {$area}";
        }?>

</body>
</html>
待"谢繁草 2024-11-15 11:47:36

POST 数组中的数组元素指的是发布到 PHP 页面的字段。在 HTML 中,确保有一个名为“radius”的文本输入,并将以下代码放入 PHP 页面中:

<?php
$rad = (float) $_POST['radius']; 
$cir = $rad * 2 * pi();
$area = pow($rad, 2) * pi();

回想一下,圆的面积要求您知道半径,A(r) = π r^2。接下来,圆周将为 C(r) = 2πr。代码就是这样做的,现在 $cir 应该保存周长,$area 应该保存面积。

The array element in the POST array refers to the field that was posted to PHP page. In your HTML, make sure you have a text input called "radius" and put the following code in your PHP page:

<?php
$rad = (float) $_POST['radius']; 
$cir = $rad * 2 * pi();
$area = pow($rad, 2) * pi();

Recall the area for a circle requires that you know the radius, A(r) = π r^2. Next, the circumfrence would be C(r) = 2πr. The code does just that, and now $cir should hold the circumference, $area should hold the area.

迟月 2024-11-15 11:47:36
<html>
<head>
<title>form1</title>
</head>
<body>
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
 Enter the radius: <input type=text name='radius'>
 <input type=submit value="submit" >
 </form>
 <?php 
 $pi=3.142;

 if(!empty ($_POST['radius'])) {

 $area = $pi*$_POST{'radius'} *$_POST{'radius'};
 $perimeter = 2*$pi*$_POST{'radius'};
 echo "perimeter = {$perimeter}\n";
 echo "Area = {$area}";
 }?>




 </body>
 </html>
<html>
<head>
<title>form1</title>
</head>
<body>
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
 Enter the radius: <input type=text name='radius'>
 <input type=submit value="submit" >
 </form>
 <?php 
 $pi=3.142;

 if(!empty ($_POST['radius'])) {

 $area = $pi*$_POST{'radius'} *$_POST{'radius'};
 $perimeter = 2*$pi*$_POST{'radius'};
 echo "perimeter = {$perimeter}\n";
 echo "Area = {$area}";
 }?>




 </body>
 </html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文