Division algorithm

Superficially, the division algorithm is trivial. A computer can perform basic mathematical operations, so it would seem sufficient to take the input data (the dividend and the divisor), execute the division operation, and output the result, which is the quotient. But what if the divisor is equal to 0? We cannot divide by 0; a program that attempts to do so will terminate with an error. Our algorithm must, of course, take this into account and check whether division is feasible before attempting to divide the numbers.

alg div en

Implementation of the algorithm in the language: Pascal, C++, Java, Python, JavaScript

 

Description of the algorithm:

  1. Start - This is where our algorithm begins.
  2. Read the input data - We read the dividend x and the divisor y.
  3. Check if the divisor is equal to 0 - We check if y=0.
  4. Division is not feasible - We follow this path if the divisor is equal to 0, meaning the division cannot be performed; we output a message stating that division by 0 is not allowed.
  5. Operation block calculating the quotient - This block calculates the quotient of x divided by y. We will only reach this point if y is not equal to 0.
  6. Output the result - After calculating the quotient, we output the result stored in z (or the variable used to store the quotient).
  7. Stop - The common end point for all paths of the algorithm.