how to get the pseudoc0de for divisble by 3?
I'm not sure if I understand the question. Do you mean "how do you write pseudocode for a program that tells whether a number is divisible by 3?" div_by_3(x): return x % 3
Actually, return x % 3 will return 0 if it is divisible by 3. In a language like C++, 0 is interpreted as "false". To be clear, you probably want this to be a boolean function, so something like "divByThree(x: Integer): Boolean = return true if x mod 3 is 0, else return false". In C++, that'd be: bool divByThree(int x) { return x % 3 == 0 }.
You're totally right, I don't know what I was thinking...I think I was tired. Actually "return not x % 3" would work in Python for a function body, but the code looks counter-intuitive, heh.
Join our real-time social learning platform and learn together with your friends!