Hi, so this semester I am taking an introductory class using SciTE and the language fortran. The problem is that I am extremely struggling trying to understand even the basics. I need to write a function next_power_three which returns the first power of 3 after n.
Logical Function next_power_three
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
Where am I going wrong in this program? Any help is so greatly appreciated. Thanks
Logical Function next_power_three
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
Where am I going wrong in this program? Any help is so greatly appreciated. Thanks