Home > Backend Development > PHP Tutorial > Simple implementation method of finding pi in PHP Original, fontcolor_PHP tutorial

Simple implementation method of finding pi in PHP Original, fontcolor_PHP tutorial

WBOY
Release: 2016-07-12 08:50:56
Original
1180 people have browsed it

A simple implementation method for finding pi in PHP. Original, fontcolor

The example in this article describes a simple implementation method for finding pi in PHP. Share it with everyone for your reference, the details are as follows:

The previous article "Calculating Pi in C Language" gives a simple calculation method of pi. Here, referring to the previous code, the calculation method of calculating pi in PHP is given. The specific code is as follows:

<&#63;php
$t=1;
$pi=0;
$n=1.0;
$s=1;
while(abs($t)>1e-6)
{
 $pi=$pi+$t;
 $n=$n+2;
 $s=-$s;
 $t=$s/$n;
}
$pi=$pi*4;
printf("pi=%10.6f",$pi);
&#63;>

Copy after login

The result of the operation is:

pi= 3.141591

Copy after login

Additional: The editor here recommends a PHP formatting and beautifying typesetting tool on this website to help you layout the code in future PHP programming and increase the readability of the code:

php code online formatting and beautification tool:

http://tools.jb51.net/code/phpformat

In addition, Since php belongs to C language style, the following tool can also format php code :

C language style/HTML/CSS/json code formatting and beautification tool:
http://tools.jb51.net/code/ccode_html_css_json

Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP mathematical operation skills", "Summary of PHP operating office document skills (including word, excel, access, ppt)", "PHP array ( Array) operating skills collection", "php sorting algorithm summary", "php common traversal algorithms and techniques summary", "php data structure and algorithm tutorial", "php programming algorithm summary", "php regular expression usage summary", "Summary of PHP operations and operator usage", "Summary of PHP string usage" and "Summary of common PHP database operation skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133047.htmlTechArticleA simple implementation method for finding pi in PHP. Original, fontcolor. This article describes an example of a simple implementation method for finding pi in PHP. Share it with everyone for your reference, the details are as follows: Previous article "...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template