How to resolve the algorithm Integer comparison step by step in the Fortran programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Integer comparison step by step in the Fortran programming language

Table of Contents

Problem Statement

Get two integers from the user. Then,   display a message if the first integer is: the second integer.

Test the condition   for each case separately,   so that   all three comparison operators are used   in the code.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Integer comparison step by step in the Fortran programming language

Source code in the fortran programming language

program arithif
integer a, b

c        fortran 77 I/O statements, for simplicity
read(*,*) a, b

if ( a - b ) 10, 20, 30
10 write(*,*) a, ' is less than ', b
   goto 40

20 write(*,*) a, ' is equal to ', b
   goto 40

30 write(*,*) a, ' is greater than ', b
40 continue

end


program compare
integer a, b
c        fortran 77 I/O statements, for simplicity
read(*,*) a, b

if (a .lt. b) write(*, *) a, ' is less than ', b
if (a .eq. b) write(*, *) a, ' is equal to ', b
if (a .gt. b) write(*, *) a, ' is greater than ', b
end


program compare
integer a, b
read(*,*) a, b

if (a .lt. b) then
  write(*, *) a, ' is less than ', b
else if (a .eq. b) then
  write(*, *) a, ' is equal to ', b
else if (a .gt. b) then
  write(*, *) a, ' is greater than ', b
end if

end


program compare
integer :: a, b
read(*,*) a, b

if (a < b) then
  write(*, *) a, ' is less than ', b
else if (a == b) then
  write(*, *) a, ' is equal to ', b
else if (a > b) then
  write(*, *) a, ' is greater than ', b
end if

end program compare


  

You may also check:How to resolve the algorithm 24 game step by step in the ZX Spectrum Basic programming language
You may also check:How to resolve the algorithm Sudoku step by step in the Tcl programming language
You may also check:How to resolve the algorithm String comparison step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Sierpinski triangle/Graphical step by step in the BASIC programming language
You may also check:How to resolve the algorithm Infinity step by step in the OpenEdge/Progress programming language