# Thread: New Program

1. ## New Program

So i just got assigned two assignments, but i will just start on one for now. Anyways, the assignment is "Bruckners Formula for pi". We need to make a program that solves this equation for pi:
pi= 4/( 1 + (1^2/(2+3^2)/(2+5^2)/(2+n^2)) Sorry it was hard to write this o the computer. But we can assume the n input is odd and is non-negative. So, like the 1^2 is divided by 2+(3^2) and that part(3^2ONLY) is divided by 2+5^2 and 5^2 is divided by 2+n^2.... and so on.
Anyways, I am so confused as to where to start... i try to start on it but i just get stuck. Can someone help me conceptualize this program?

2. So pick a reasonable n, like 13. Write down your formula all the way out, and use your knowledge of the algebraic order of operations to figure out the order in which things must happen. Once you have that, look for a pattern that you can exploit in a loop.

3. still clueless... can anyone help me get on the right path? i tried working it out, but when i go back to the computer i get nowhere.

4. If you can't do it on paper, there's no way you're going to get it in the computer. Let's check what you should have gotten for 13:
13^2 = 169
2 + this = 171
11^2 = 121
last line/two lines ago = 0.7076 (and so on)
2 + this = 2.7076
9^2 = 81
last line/two lines ago = 29.9158 (and so on)
2 + this = 31.9158
7^2 = 49
last line/two lines ago = 1.5353
2 + this = 3.5353
5^2 = 25
last line/two lines ago = 7.072
2 + this = 9.072
3^2 = 9
last line/two lines ago = 0.9921
2 + this = 2.9921
1^2 = 1
last line/two lines ago = 0.3342

1 + this = 1.3342
4/this = 2.998

I've never come across Bruckner's formula nor can I find it in any reference, so I don't know how fast it actually approaches pi, but that seems to be what we get.

Hopefully you can see a pattern.

5. YES! i can! thanks so much for the help... im thinkin it should be easy to do program the math inside the loop, but what should the condition to enter the loop be? i know the number they enter determines howm nay times but is it exactly 13 times? idk im confused there

6. You should have the number of decimal places determine when the loop ends, imo. Though this formula is VERY slow, so I wouldn't go all crazy and try to make the world record for digits of pi calculated.

7. Originally Posted by Lucid15
YES! i can! thanks so much for the help... im thinkin it should be easy to do program the math inside the loop, but what should the condition to enter the loop be? i know the number they enter determines howm nay times but is it exactly 13 times? idk im confused there
Since the variable starts at <whatever they enter> and goes down to 1, I'm thinking it stops when you get to 1.

8. ok so they enter 13 and i minus two from that number until it reaches 1 and then the loop should be over correct?

9. so i tried to get the pow function to work, am i doing this wrong?
Code:
```#include <FPT.h>
int main()
{
double n,a,b;
n=inD();
a=1;
b=1;
while(n>=1){
a= pow(n,2);

outD(a);
}

}```

10. pow is in math.h. I have no idea what you think that code is supposed to do, so all I can say is that you have an all-or-nothing loop; n doesn't change inside it, so if you get in you can never get out.

11. I think it is in my header file now, cause it works, i got rid of the loop.

12. Well i tried it out, but im getting wayyyyyyyy to big of a answer..... with this code
Code:
```#include <FPT.h>
int main()
{
double n,a,b,c;
n=inD();
a=1;
b=1;
while(n>1){
a= pow(n,2);
a=a+2;
n=n-1;
b=pow(n,2);
c=(b/a) +2;
n=n-1;
}
if(n==1){
a=pow(n,2);
c=(c/a)+1;
}

outD(4/c);

}```

13. If n is supposed to go down by 2, why do you do n=n-1? Edit: Also, the body of your loop has way more than two lines in it, which is a problem.

14. Ok problem fixed with the -1 i have no idea what i was thinking, and does it really matter how many lines are within the loop? i guess hes never told us that.

15. Ok now my answer seems to get a little small.. for 13 i get: 1.2 and for any other higher number i get 1.8 and thats as high as it gets

Popular pages Recent additions