Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran Help

  1. Mar 31, 2013 #1
    Hi all, I just started learning computer languages and Im having an extremely difficult time understanding it all. I need to write a function which gives the next power of three after input n.

    Logical Function next_power_three(n)
    Integer::n,p
    if (n<1) then
    next_power_three=.false.
    return
    endif
    p=1
    do while (.not. p>n)
    if (n==p) then
    next_power_three=.true.
    p=p+1
    return
    Else
    p=3*p
    endif
    enddo
    next_power_three=.false.
    endfunction

    program test_next_power_three
    integer:: is_power_of_three
    print *,'02 ->', next_power_three(2)
    print *,'03 ->', next_power_three(3)
    print *,'28 ->',next_power_three(28)
    endprogram

    This is what I have, but i cant see where i went wrong. Any help would be greatly appreciated.
     
  2. jcsd
  3. Mar 31, 2013 #2
    Take a look at the reply to your post in Tek-Tips.
     
  4. Apr 3, 2013 #3
    Can you give some expected output?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran Help
  1. Fortran Help (Replies: 1)

  2. Fortran help (Replies: 0)

  3. Help in fortran (Replies: 2)

  4. [Fortran] help (Replies: 2)

  5. FORTRAN Help (Replies: 1)

Loading...