Skip to content
Advertisement

Divide by zero, can’t find the problem in this program which runs Euclid’s algorithm to find the greatest common divisor

JavaScript

I followed the steps of Euclid’s algorithm but I was stunned when a divide by zero problem appeared. I don’t know how it can happen.

Advertisement

Answer

The problem is with the below two lines.

JavaScript

First statement will make a[0] as 0 since c is 0. Next statement will be 1/0.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement