posted 7 years ago

Hello every one i need to help me in understanding this small program

...you can approximate by using the following series

∏=4(1-1/3+1/5-1/7+1/9-1/11+1/13-.....-1/(2i-1)+1/(2i+1))

write a program that displays the value for i=10000,20000,....,and 100000

I've developed this code to solve the problem

but i don't know how can i compute the value when i is equal to 10000,20000,.....,and 100000

note that the output of my program is

The value of p is 3.1415926517266946

...you can approximate by using the following series

∏=4(1-1/3+1/5-1/7+1/9-1/11+1/13-.....-1/(2i-1)+1/(2i+1))

write a program that displays the value for i=10000,20000,....,and 100000

I've developed this code to solve the problem

but i don't know how can i compute the value when i is equal to 10000,20000,.....,and 100000

note that the output of my program is

The value of p is 3.1415926517266946

I Hear I Forget, I See I Remember, I Do I Understand.

posted 7 years ago

no this isn't my question

is this code I've written solve the problem?

and what about "compute the value when i is equal to 10000,20000,.....,and 100000"

this is supposed to be implemented in my code

Do you mean that double doesn't have enough precision to handle the larger values of i

no this isn't my question

is this code I've written solve the problem?

and what about "compute the value when i is equal to 10000,20000,.....,and 100000"

this is supposed to be implemented in my code

I Hear I Forget, I See I Remember, I Do I Understand.

posted 7 years ago

Ah, got it. The second part of your for statement should be the limit. Comparing i to a value computed from i isn't a good idea. For any non-negative value of i, i < 2 * i + 1 will always be true. You want something more like:

That's not exactly right though, because your i isn't being used exactly the same way it's used in the formula. I'd advise changing the code so it matches the formula more closely and see if you can dispense with the count variable entirely. Try a low limit of i and put in some print statements at first to help you get the code right.

That's not exactly right though, because your i isn't being used exactly the same way it's used in the formula. I'd advise changing the code so it matches the formula more closely and see if you can dispense with the count variable entirely. Try a low limit of i and put in some print statements at first to help you get the code right.

posted 7 years ago

I take your advice and I've improved my code to the following

here I've used nested loops..........the outer to control the value of i

and the inner to control the value of x(denominator) and gave me the result i really want.

what is your opinion???

thanks.

I'd advise changing the code so it matches the formula more closely

I take your advice and I've improved my code to the following

here I've used nested loops..........the outer to control the value of i

and the inner to control the value of x(denominator) and gave me the result i really want.

what is your opinion???

thanks.

I Hear I Forget, I See I Remember, I Do I Understand.

posted 7 years ago

Actually, I was trying to nudge you towards a simpler program, and you made it more complex. Keep in mind that when i = 1, then 2*i - 1 is 1 and 2*i + 1 is 3. When i = 2, then 2*i - 1 is 3, and 2*i+1 is 5. you should be able to generate your whole series just by changing the value of i. The only variables you should need then are i and a sum to keep a running total.