program Aug02_2002 implicit none integer::range,i,j,k,gcd,ell,blank_count ! Notice that the type of plus_plus does not have to be specified real::round,v,m character::letter_grade character(40)::myword print*,sqrt(2.0),round(sqrt(2.0),3) do i = 50,99,7 print*,"A numeric score of ",i," yields a letter grade of ",letter_grade(i) end do ell = 18 j = 5 if(plus_plus(j) == 6) print*,'plus_plus(j) == 6' print*,'j = ',j if(plus_plus(5) == 6) print*,'plus_plus(5) == 6' ! Illegal Statement print*,'5 = ',5 myword = "I think therefore I am" print*,"The word 'myword' has",blank_count(myword),"blanks" print*,"and should be written as '",trim(myword),"'" call get_volume_mass(v,m) print*,"The density is ",m/v call plus_equals(ell,j+3) print*,"ell is now",ell print*,"writing 354 in base 2" call base_write(354,2) contains integer function plus_plus(n) implicit none integer::n n = n+1 print*,"ell = ",ell ! within the scope of ell plus_plus = n end function plus_plus end program Aug02_2002 integer function range(a,b) implicit none integer,intent(in)::a,b range = abs(a-b) end function range real function round(amount,n) implicit none integer,intent(in)::n real,intent(in)::amount integer,parameter::base = 10 integer::factor factor = base**n ! print*,"ell = ",ell ! NOT within the scope of ell round = nint(amount*factor)/real(factor) end function round real function num_bac(initialpop,growthrate,time) implicit none real,intent(in)::initialpop,growthrate,time num_bac = initialpop*exp(growthrate*time) end function num_bac character function letter_grade(numericscore) implicit none integer,intent(in)::numericscore integer,parameter::minA = 90, minB = 80, minC = 70, minD = 60 if(numericscore >= minA) then letter_grade = 'A' else if(numericscore >= minB) then letter_grade = 'B' else if(numericscore >= minC) then letter_grade = 'C' else if(numericscore >= minD) then letter_grade = 'D' else letter_grade = 'F' end if end function letter_grade recursive integer function gcd(a,b) result (g) implicit none integer,intent(in)::a,b if(a > b)then g = gcd(b,a) else if (a < 0) then g = gcd(-a,b) else if (a == 0) then g = b else g = gcd(mod(b,a),a) end if end function gcd integer function blank_count(word) implicit none character(*),intent(in)::word character,parameter::blank = " " integer::i blank_count = 0 do i = 1,len(word) if(word(i:i) == blank) blank_count = blank_count + 1 end do end function blank_count subroutine get_volume_mass(volume,mass) implicit none real,intent(out)::volume,mass do print*,"Please enter the volume followed by the mass" read*,volume,mass if ((volume > 0) .and. (mass > 0)) exit print*,"Sorry, both volume and mass must be positive. Please try again:" end do end subroutine get_volume_mass subroutine plus_equals(x,y) ! adds y to x implicit none integer,intent(inout)::x integer,intent(in)::y x = x+y end subroutine plus_equals recursive subroutine base_write(number,base) ! writes number in that base integer,intent(in)::number,base ! input condition: base does not exceed 10 print*,"SUBROUTINE base_write IS NOT AVAILABLE YET" end subroutine base_write