[Fortran] 纯文本查看 复制代码
INTEGER SIGN
READ *, N, X
SUM = X
SIGN = 1
FACT = 1.0
P = X
DO 10, I=2,N
SIGN = (-1)*SIGN
FACT = FACT * (2.0*I-2) * (2.0*I-1)
P = P * X**2
SUM = SUM + SIGN*P/FACT
10 CONTINUE
PRINT *, SUM
END
[Fortran] 纯文本查看 复制代码
Program www_fcode_cn
Implicit None
INTEGER SIGN , i , n
Real :: x , sum , fact , p
READ *, N, X
SUM = X
SIGN = 1
P = X
DO I = 2 , N
SIGN = (-1)*SIGN
!FACT = FACT * (2.0*I-2) * (2.0*I-1)
P = P * X**2 / ( (2.0*I-2) * (2.0*I-1) )
SUM = SUM + SIGN * P
End Do
PRINT *, SUM
End Program www_fcode_cn