나는 C++을 배우고 있으며, pi (link : https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_algorithm)를 근사화하기 위해 위키 백과에서 Gauss-Legendre 알고리즘을 발견했습니다. C++로 구현하려고했지만 결과가 나오지 않습니다. 다음은 코드입니다 : 내가 도움을 검색하면왜 Gauss Legendre 알고리즘을 C++로 구현해도 결과가 나오지 않습니까?
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <iomanip.h>
int main()
{
clrscr();
long double a0 = 1,
b0 = 1/sqrt(2),
t0 = 1/4,
p0 = 1,
an, bn, pn, tn;
int i = 0;
while(i < 3)
{
an = (a0 + b0)/2;
bn = sqrt(a0 * b0);
tn = t0 - (p0 * (pow((a0 - an), 2)));
pn = 2 * p0;
a0 = an;
b0 = bn;
t0 = tn;
p0 = pn;
}
long double pi = (pow((an + bn), 2))/(4 * tn);
cout<<pi;
getch();
return 0;
}
내가 이걸 발견하지만, 나에게 다른 알고리즘 것 - gauss-legendre in c++
UPDATE : i
증가 프로그램이 잘못된 결과를 제공 추가 한 후합니다.
구체적으로 작성하십시오. – Alex
이 링크를 참조 할 수 있습니다. https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_algorithm –