/*************************************************************************************************************************************/ /* */ /* C A L C U L D E ' P I ' P A R L A F O R M U L E D E */ /* S A L A M I N - B R E N T Q U A D R A T I Q U E : */ /* */ /* */ /* Author of '$xtc/pi_SalBr2.01$c' : */ /* */ /* Jean-Francois COLONNA (LACTAMME, AAAAMMJJhhmmss). */ /* */ /*************************************************************************************************************************************/ #include <stdio.h> extern double sqrt(); extern double pow(); #define UN 1.0 #define DEUX 2.0 #define ITER 4 main() { double k; double A_k_1=UN; double A_k; double B_k_1=UN/sqrt(DEUX); double B_k; double C_k; double S_k_1=UN/DEUX; double S_k; double P_k; double pi; for (k=1 ; k<=ITER ; k++) { A_k = (A_k_1 + B_k_1)/DEUX; B_k = sqrt(A_k_1*B_k_1); C_k = (A_k*A_k) - (B_k*B_k); S_k = S_k_1 - (pow(DEUX,k)*C_k); P_k = (DEUX*A_k*A_k)/S_k; A_k_1 = A_k; B_k_1 = B_k; S_k_1 = S_k; /* Formule donnee a la page 52 du numero 1, volume 19 de The Mathematical Intelligencer. */ } pi = P_k; printf("\n pi = %.12f",pi); }