- 2074 Asoj · 8 marks
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
- The name comes from FORmula TRANslation; it was the first widely used high-level language (IBM, 1957).
- It is designed for scientific and engineering calculation, with strong numerical and mathematical support (real, double precision and complex types).
- It is a compiled language, so programs run fast.
- The syntax is simple and close to mathematical formulas (
A = B*C + D). - It has good array handling and many built-in (intrinsic) functions.
- It supports modular programming with functions and subroutines, and has formatted input/output.
- FORTRAN 77 uses a fixed-form layout (columns 1–72); later versions (90 and above) have free form, modules and pointers.
- 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)
Related questions
- Structure of a FORTRAN program · Computer Programming, chapter 11 · asked 5×
- Computer program and programming · Computer Programming, chapter 2
- Quadratic equation roots in FORTRAN · Computer Programming, chapter 11 · asked 2×
- GOTO types; sum of series program · Computer Programming, chapter 11
- Sort array ascending in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Largest of n numbers in FORTRAN · Computer Programming, chapter 11
- Program for RK-4 first order IVP · Numerical Method, chapter 6
- Calorific value of fuel by Dulong's formula · Internal Combustion Engines, chapter 3
- First four terms of Taylor series about z = 2 · Applied Mathematics, chapter 1
- Direct programming of a first-order filter · Digital Control System, chapter 4