• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

What is the formula to find Pi?

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

alfa147x

Lifer
Jul 14, 2005
29,307
106
106
Originally posted by: txrandom
I can write a small program to do it if you are interested. It uses Leibnez Series.

can you send me just the code? What language ?

nvm i did nt notice the pm
 

alfa147x

Lifer
Jul 14, 2005
29,307
106
106
Here I just made an application that prints out math.pi

here is the code:
Code:
/*
 * Main.java
 *
 * Created on December 14, 2006, 8:15 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import java.lang.Math;

/**
 *
 * @author Bonsai
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Object number = Math.PI;
        
        
        System.out.println(number);
        
        // TODO code application logic here
    }
    
}


the output is:

compile:
run:
3.141592653589793
BUILD SUCCESSFUL (total time: 3 seconds)


 

alfa147x

Lifer
Jul 14, 2005
29,307
106
106
Oh by the way when you give me some kind of math formula, could you please explain how to insert it into Java, because i am taking Algebra 2 and i am in first semester AP Computer Science (Java)
 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
167
111
www.slatebrookfarm.com
There are quite a few different methods for calculating pi. Some converge incredibly rapidly, others take a little while. (there's one formula in particular that reaches 10's of 1000's of digits after just a few iterations.)
 

WildHorse

Diamond Member
Jun 29, 2003
5,006
0
0
Originally posted by: Don Rodriguez
Hit the Pi key on a calculator.
Or in caase yor cheap calculator doesn't have a pi key, the quick & simple approximation I use is:
pi ? 355 / 113


 

hypn0tik

Diamond Member
Jul 5, 2005
5,866
2
0
Originally posted by: BrokenVisage
Originally posted by: Aflac
Originally posted by: Shawn
22/7

Might want to try that in a calculator.

Yeah, pretty sure that's another non-repeating, non-terminating decimal.. it's just very close to pi.

I can't tell if you're being serious or joking. A rational number (integer/integer, denominator is not 0) always has a decimal representation that's either terminating or repeating.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Originally posted by: alfa147x
Here I just made an application that prints out math.pi

here is the code:
Code:
/*
 * Main.java
 *
 * Created on December 14, 2006, 8:15 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import java.lang.Math;

/**
 *
 * @author Bonsai
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Object number = Math.PI;
        
        
        System.out.println(number);
        
        // TODO code application logic here
    }
    
}


the output is:

compile:
run:
3.141592653589793
BUILD SUCCESSFUL (total time: 3 seconds)

You are teh code genius.
 

Vertimus

Banned
Apr 2, 2004
1,441
0
0
Originally posted by: tfinch2
Originally posted by: alfa147x
Here I just made an application that prints out math.pi

here is the code:
Code:
/*
 * Main.java
 *
 * Created on December 14, 2006, 8:15 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import java.lang.Math;

/**
 *
 * @author Bonsai
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Object number = Math.PI;
        
        
        System.out.println(number);
        
        // TODO code application logic here
    }
    
}


the output is:

compile:
run:
3.141592653589793
BUILD SUCCESSFUL (total time: 3 seconds)

You are teh code genius.

Haha... took 3 seconds to output a 20-character string :p
 

silverpig

Lifer
Jul 29, 2001
27,703
12
81
n = 1
while (n > -1)

pi = 4*(-1)^n / (2*n+1)
System.out.println(pi)
n = n+1


or something to that effect