program t03 implicit none real::x integer::i,n character(16)::form = '(x,i2,"! = ",i9)' call rms(2.0,4.0,x) print'(a,f5.2)',"The rms is",x do i = -20,20 if (is_perfect_square(i)) print*,i,"is a perfect square" end do do i = 0,12 print form,i,factorial(i) end do contains subroutine rms(x,y,z) implicit none real, intent(in)::x,y real, intent(out)::z z = sqrt((x**2+y**2)/2) end subroutine rms logical function is_perfect_square(n) implicit none integer,intent(in)::n is_perfect_square = n >= 0 .and. nint(sqrt(real(abs(n))))**2 == n end function is_perfect_square !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! The type of a function can be declared in the header line. This ! ! alternative method is shown as a comment line below. ! ! If this alternative is used, delete the header line and also the ! ! line that specificies integer type for the result identifier. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! recursive integer function factorial(n) result(fact) recursive function factorial(n) result(fact) implicit none integer,intent(in)::n integer::fact if (n < 0) then print 10, "Error in function factorial: negative argument not allowed" 10 format(a) else if (n == 0) then fact = 1 else fact = n * factorial(n-1) end if end function factorial end program t03