- Feb 21, 2004
- 3,875
- 3
- 81
Ok, so I thought Super PI was cool and wanted to make my own. So, I broke out the ol' C programming and fired up a simple program. However, it doesn't work.
Here's the algorithm:
http://cage.rug.ac.be/~hvernaev/Gauss-L.html
I was wondering if the limitations on the double number type could cause unintelligible results, or if maybe someone could spot a blatant error in my code?
- Thanks in advance
Here's my code by the way:
/* Program to calculate PI */
#include<stdio.h>
#include<math.h>
int main(void)
{
double a=1, b, t=0.25, x=1, y;
int its, i;
b = 1/sqrt(2);
printf("\n Please enter the number of iterations: >");
scanf("%u", &its);
for(i=0; i<its; i++)
{
y = a;
a = (a + b) / 2;
b = sqrt(b * y);
t = t - x*(y - a)*(y-a);
x = 2*x;
}
printf("\nPI = %u\n\n", ((a+b)*(a+b)/(4*t)));
return(0);
}
Here's the algorithm:
http://cage.rug.ac.be/~hvernaev/Gauss-L.html
I was wondering if the limitations on the double number type could cause unintelligible results, or if maybe someone could spot a blatant error in my code?
- Thanks in advance
Here's my code by the way:
/* Program to calculate PI */
#include<stdio.h>
#include<math.h>
int main(void)
{
double a=1, b, t=0.25, x=1, y;
int its, i;
b = 1/sqrt(2);
printf("\n Please enter the number of iterations: >");
scanf("%u", &its);
for(i=0; i<its; i++)
{
y = a;
a = (a + b) / 2;
b = sqrt(b * y);
t = t - x*(y - a)*(y-a);
x = 2*x;
}
printf("\nPI = %u\n\n", ((a+b)*(a+b)/(4*t)));
return(0);
}