I am trying to make a C ++ application to calculate pi for me. I tried to implement the Chudnovsky formula without luck.
Here is my code:
#include <iostream> #include <cmath> long fac(long num) { if (num == 1) return 1; return fac(num - 1) * num; } int main() { using namespace std; double pi; for (long k = 0; k < 10; k++) { pi += (pow(-1, k) * fac(6 * k) * (13591409 + (545140134 * k))) / (fac(3 * k) * pow(fac(k), 3) * pow(640320, 3 * k + 3/2)); } pi *= 12; cout << 1 / pi << endl; system("pause"); return 0; }
The purpose of this was for the program to output 10 iterations of the Chudnovsky formula. Instead, I got the following:
call of overloaded `pow(int, long int&)' is ambiguous
source share