How to resolve the algorithm Greatest common divisor step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Greatest common divisor step by step in the Icon and Unicon programming language

Table of Contents

Problem Statement

Find the greatest common divisor   (GCD)   of two integers.

Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Greatest common divisor step by step in the Icon and Unicon programming language

Source code in the icon programming language

link numbers   # gcd is part of the Icon Programming Library
procedure main(args)
    write(gcd(arg[1], arg[2])) | "Usage: gcd n m")
end


procedure gcd(i,j)		#: greatest common divisor
   local r

   if (i | j) < 1 then runerr(501)

   repeat {
      r := i % j
      if r = 0 then return j
      i := j
      j := r
      }
end


  

You may also check:How to resolve the algorithm Find limit of recursion step by step in the MUMPS programming language
You may also check:How to resolve the algorithm Mandelbrot set step by step in the Ada programming language
You may also check:How to resolve the algorithm Klarner-Rado sequence step by step in the jq programming language
You may also check:How to resolve the algorithm Order disjoint list items step by step in the Julia programming language
You may also check:How to resolve the algorithm Plasma effect step by step in the Ceylon programming language