Examples
- Write a program that computes and displays the squares of the integers between -1000 and 1000, inclusive.
- Open a Secure Shell terminal window.
- Change to the directory of your source file.
- Type
vi squares1000.f
and press Enter. - Enter FORTRAN commands that implement this algorithm.
- for each integer from -1000 to 1000
- display the integer and its squared value
- for each integer from -1000 to 1000
- Type [Esc] and [Shift-ZZ] to save and exit the source file.
- Compile the program using
gfortran squares1000.f
. - Run the program by typing
a.out
Here's one possible FORTRAN solution to this problem.
c c Calculates and displays the squares of the numbers from c -1000 to 1000. c program squares1000 integer i do 100 i = -1000,1000 write(*,*) i, "^2=", i*i 100 continue end
If there are no compiler errors, you should be able to run the file
a.out
and see the values of the squares of the integers from -1000 to 1000.If there are compile-time errors, you must fix each error before a valid executable can be be built. Each error includes a message and a line number and location of where the error was recognized.
You may have to fix runtime (or logic) erros also, once you see the output your program produces. If it is not the values you expect, make any necessary changes to get the list of values you desire.