Initializing help system before first use

Largest common divisor


Type: Programming
Rating: 2 (easy-medium)
Description: Find the largest common divisor of two integer numbers
  • recursive function calls
  • if-then-elif-then-else statement
  • alternative formulation using a 'while' loop
File(s): lcdiv1.mos


lcdiv1.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file lcdiv1.mos 
   ``````````````` 
   Using the `while` loop.
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2001
*******************************************************!)

model Lcdiv1

 declarations
  A,B: integer
 end-declarations

 write("Enter two integer numbers:\n  A: ")
 readln(A)
 write("  B: ")
 readln(B)

 while (A <> B) do
  if (A>B) then 
   A:=A-B 
  else B:=B-A 
  end-if
 end-do

 writeln("Largest common divisor: ", A)

end-model