i was trying to make a program that uses the chudnovsky algorithm to calculate pi with this code:
#include <cmath>
#include <iostream>
#include <cstdlib>
using namespace std;
float fac (float num)
{
float result=1;
for (float i=1; i<=num; ++i)
result=result*=i;
return result;
}
int main()
{
double pi=0;
float k=0;
float t[2];
cout << "Enter the number of terms:" <<endl;
cin >> k;
while (k<=10)
{
t[1]=fac(k);
t[2]=3*k+(3/2);
pi += fac(6*k)*(13591409+545140134*k)/fac(3*k)*pow(t[1],3)*pow((640320),t[2]);
k++;
}
cout << 1/(pi*12)<<endl;
system("pause");
return 0;
}
at first it outputted -1.#IND. Then after changing "cout << pi << endl;" to " cout << 1/(pi*12 << endl;" (which i had forgot about), got zero every time. any help?