I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

CodeCogs\′s Photo
23 Nov 11, 11:56PM
You've made a couple of errors:

When you declare "double x" you should really also assign it to zero, i.e.
long double x=0;

In the loop, your code is all wrong, try:
for (int n = 2; n <= i; n++) 
{ 
  x += 1/pow(n,2.0);
}
pi =sqrt(6*(1+x));

You'l notice you don't need n=1, because you've included this result explicitly in the last line above. You don't need to use long int, the int will be easily sufficient for anything you need. If you're going to use a long double for pi, then you should use the same for x.

Hope this helps.
Currently you need to be logged in to leave a message.