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.(adsbygoogle = window.adsbygoogle || []).push({});

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.

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Fortran Help

Loading...

Similar Threads - Fortran Help | Date |
---|---|

I need help in Fortran please -- Bairstow's method & Newton-Raphson | Nov 26, 2016 |

Need help with FORTRAN | Jun 8, 2016 |

Fortran compile error I can't figure out | Jan 15, 2016 |

Help about Fortran | Sep 13, 2015 |

[Fortran] Help Reading Complex 2D data | Jul 14, 2015 |

**Physics Forums - The Fusion of Science and Community**