Fortran Finding the Next Power of Three with a Logical Function

  • Thread starter Thread starter wellnis20
  • Start date Start date
  • Tags Tags
    Function Power
AI Thread Summary
The discussion centers around a user struggling with a function to determine the next power of three after a given input n. The provided code attempts to implement this logic but contains errors. The user is seeking assistance in identifying these mistakes. A suggestion is made to clarify the expected output for the function, which could help in troubleshooting the code. The conversation emphasizes the importance of understanding the logic behind the function and the need for clear output expectations to facilitate debugging.
wellnis20
Messages
1
Reaction score
0
Hi all, I just started learning computer languages and I am 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 can't see where i went wrong. Any help would be greatly appreciated.
 
Technology news on Phys.org
Take a look at the reply to your post in Tek-Tips.
 
Can you give some expected output?
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
19
Views
6K
Replies
18
Views
2K
Replies
10
Views
1K
Replies
11
Views
2K
Replies
8
Views
2K
Replies
29
Views
3K
Back
Top