next up previous contents
Next: Problems Up: A quick tour of Previous: Repetitive action   Contents

Application to DO loops: Fahrenheit to Celsius

Write a program that converts the temperature from Fahrenheit degrees to Celsius degrees (centigrades). The steps are:
  1. Problem formulation
  2. Algorithm
  3. Implementation
  4. Run, and if the result is wrong, loop back.
program temp_conv
implicit none
  integer :: n    ! no. of temperatures to convert
  real    :: f,c  ! temp. values in F,C
  integer :: i    ! loop counter
  print*,'No. of conversions='
  read*,n
  do i=1,n
    print*,'Fahrenheit temp. no ',i,'='
    read*,f
    c=9.0/5.0*(f-32)
    print*,f,' F is ',c,' C'
  end do
end program temp_conv



Adrian Sandu 2001-08-26