Fortran – Perform Sum of Given Numbers

email me

I used the registered version of the Simply Fortran compiler, here: simplyfortran-3.0.msi, simplyfortran-2.35.msi; also, try the online Fortran compiler.

PROGRAM Sum

! inhibit older feature
IMPLICIT NONE

	! declare numbers
    REAL X,Y,Z
	
	! input X
    PRINT *,"Enter first number: "
    READ *, X
	
	! input Y
    PRINT *,"Enter second number: "
    READ *, Y
    
	! perform calculation
	Z = X + Y
	
	! output sum
    PRINT *,"Sum of X + Y = ", Z
	
	READ(*,*)
	
END PROGRAM Sum

 

Output

 

Notes

Learn more, Fortran language

https://pinetools.com/syntax-highlighter

 

Types of Variables

Integer: It can hold only integer values.

Real: It stores the floating point numbers.

Complex: It is used for storing complex numbers.

Logical: It stores logical Boolean values.

Character: It stores characters or strings.