# Understanding small program

Page 1 of 1

## 1 Replies - 709 Views - Last Post: 18 October 2010 - 09:27 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=195630&amp;s=097fc2974e48eebcffd0e37ec276d04a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Moustafa taha

• New D.I.C Head

Reputation: 0
• Posts: 9
• Joined: 28-September 10

# Understanding small program

Posted 18 October 2010 - 04:10 PM

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
```public static void main(String[] args) {
int count=1;
double sum=0;
for(int i=1;i<2*i+1;i+=2)
{
if(count % 2==0)
sum-=1.0/i;
else
sum+=1.0/i;
count++;
}
double p=4*sum;
System.out.println("The value of p is "+p);
}

```

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

Is This A Good Question/Topic? 0

## Replies To: Understanding small program

### #2 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

## Re: Understanding small program

Posted 18 October 2010 - 09:27 PM

try using BigDecimal to give you a little more memory for those hefty numbers =)

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }