/******************************************************************** * This program computes Bernoulli number Bn using subroutine BERNOA * * ----------------------------------------------------------------- * * SAMPLE RUN: * * Compute Bernoulli number Bn for n = 0,1,...,10. * * * * Please enter Nmax: 10 * * * * n Bn * * -------------------------- * * 0 1.000000000000 * * 1 -0.500000000000 * * 2 0.166666666667 * * 4 -0.033333333333 * * 6 0.023809523810 * * 8 -0.033333333333 * * 10 0.075757575758 * * -------------------------- * * * * ----------------------------------------------------------------- * * REFERENCE: "Fortran Routines for Computation of Special Functions,* * jin.ece.uiuc.edu/routines/routines.html". * * * * C++ Release By J-P Moreau, Paris. * * (www.jpmoreau.fr) * ********************************************************************/ #include #include #define NMAX 100 double B[NMAX]; int K,N; void BERNOA(int N, double *BN) { /*====================================== Purpose: Compute Bernoulli number Bn Input : n --- Serial number Output: BN(n) --- Bn ======================================*/ int J,K,M; double R,S; BN[0]=1.0; BN[1]=-0.5; for (M=2; M<=N; M++) { S=-(1.0/(M+1.0)-0.5); for (K=2; K