Advertisement
7_2009-2012 Math #220743

Precise Calculation of Pi

This code calculates an estimated value of Pi using the Leibnitz series (which is basically a power series expansion of a trigonometric function which allows to estimate Pi very well)

AI

KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Quellcode
original-source
#include <iostream.h>
#include <math.h>
#define NUM_OF_ELEMENTS 20000
int main()
{
 double pi = 0;
 // Calculating pi/4
 for (long int n = 1; n <= NUM_OF_ELEMENTS; n++)
 {
 pi += (double) pow(-1, n+1)/(2*n-1);
 }
 // Calculating pi
 pi *= 4;
 cout << "Estimated PI value (" << NUM_OF_ELEMENTS << " elements of Leibnitz series): "<< pi;
 return 0;
}
<?php
Class yahoo
{
function get_stock_quote($symbol)
{
$url = sprintf("http://finance.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgv" ,$symbol);
$fp = fopen($url, "r");
if(!fp)
{
echo "error : cannot recieve stock quote information";
}
else
{
$array = fgetcsv($fp , 4096 , ', ');
fclose($fp);
$this->symbol = $array[0];
$this->last = $array[1];
$this->date = $array[2];
$this->time = $array[3];
$this->change = $array[4];
$this->open = $array[5];
$this->high = $array[6];
$this->low = $array[7];
$this->volume = $array[8];
}
}
}
$quote = new yahoo;
$quote->get_stock_quote("MSFT");
echo ("<B>$quote->symbol</B><br>");
echo ("<B>$quote->time</B><br>");
echo ("<B>$quote->date</B><br>");
echo ("<B>$quote->last</B><br>");
echo ("<B>$quote->change</B><br>");
echo ("<B>$quote->high</B><br>");
echo ("<B>$quote->low</B><br>");
?>
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine