| Download
Github repo cloud-examples: https://github.com/sagemath/cloud-examples
Project: Support and Testing
Views: 8055License: MIT
program cylinder12! source: https://en.wikibooks.org/wiki/Fortran/Fortran_examples3! Calculate the surface area of a cylinder.4!5! Declare variables and constants.6! constants=pi7! variables=radius squared and height89implicit none ! Require all variables to be explicitly declared1011integer :: ierr12character(1) :: yn13real :: radius, height, area14real, parameter :: pi = 3.1415926535897931516interactive_loop: do1718! Prompt the user for radius and height19! and read them.2021write (*,*) 'Enter radius and height.'22read (*,*,iostat=ierr) radius,height2324! If radius and height could not be read from input,25! then cycle through the loop.2627if (ierr /= 0) then28write(*,*) 'Error, invalid input.'29cycle interactive_loop30end if3132! Compute area. The ** means "raise to a power."3334area = 2 * pi * (radius**2 + radius*height)3536! Write the input variables (radius, height)37! and output (area) to the screen.3839write (*,'(1x,a7,f6.2,5x,a7,f6.2,5x,a5,f6.2)') &40'radius=',radius,'height=',height,'area=',area4142yn = ' '43yn_loop: do44write(*,*) 'Perform another calculation? y[n]'45read(*,'(a1)') yn46if (yn=='y' .or. yn=='Y') exit yn_loop47if (yn=='n' .or. yn=='N' .or. yn==' ') exit interactive_loop48end do yn_loop4950end do interactive_loop5152end program cylinder5354