Skip to main content

FORTRAN characteristics; compute π

Short answer

FORTRAN is a high-level compiled language for scientific computing, with strong numerical support, array handling, intrinsic functions, formatted I/O, and modularity. Program to compute pi: sum the series 4(1 - 1/3 + 1/5 - 1/7 + ...) for 25 terms using a DO loop with term (-1)^(k+1)/(2k-1). The computed value is approximately 3.181577.

What are the characteristics of FORTRAN Programming? Write a program in FORTRAN to calculate the value of π by evaluating the following formula for the first 25 terms. π = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - …)

Characteristics of FORTRAN

  1. The name comes from FORmula TRANslation; it was the first widely used high-level language (IBM, 1957).
  2. It is designed for scientific and engineering calculation, with strong numerical and mathematical support (real, double precision and complex types).
  3. It is a compiled language, so programs run fast.
  4. The syntax is simple and close to mathematical formulas (A = B*C + D).
  5. It has good array handling and many built-in (intrinsic) functions.
  6. It supports modular programming with functions and subroutines, and has formatted input/output.
  7. FORTRAN 77 uses a fixed-form layout (columns 1–72); later versions (90 and above) have free form, modules and pointers.
  8. It is standardised and portable, and has a large library of tested scientific code.

Program: π by the series π = 4 (1 − 1/3 + 1/5 − 1/7 + …) for 25 terms

The K-th term is (−1)^(K+1) / (2K − 1). (-1.0)**(K+1) gives the alternating sign.

      PROGRAM PIVAL
      REAL S, PI
      INTEGER K
      S = 0.0
      DO 10 K = 1, 25
         S = S + (-1.0)**(K+1) / (2.0*K - 1.0)
   10 CONTINUE
      PI = 4.0 * S
      WRITE(*,20) PI
   20 FORMAT(' PI = ', F10.6)
      STOP
      END

Result: with 25 terms the program gives about 3.181577 (calculated separately). The series converges slowly, so 25 terms give only one correct decimal place; the true value is 3.141593.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 11 questions →