• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Program check

Reel

Diamond Member
I am working on a homework problem that asks me to prove that two different methods of finding the greatest common denominator work. One of them is clear that it works. The other it seems to me does not work. I even went so far as to write a java program to check this out. Can someone give this a glance and tell me if I am mistaken or not please?

It seems to me that no matter what this program will always end up in a divide by 0 situation. Take two easy numbers: 21 and 7. We can glance at this and say the greatest common divisor is 7. However, the program does 21 mod 7 which yields 0. Then next loop 7 mod 0 which is a divide by 0.

Pseudocode:
 
Thanks. I don't have to fix it. I just wanted to make sure I wasn't crazy and that there was a problem with the pseudocode provided by the book.
 
Interesting trick question -- without checks for 0 result in both the if and else I think this will always fail unless i==j. Unless they've defined "mod" differently from how it behaves in C, C++, Pascal, and BASIC.
 
Back
Top