gornox_zx has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; my @thing; my @thing1; my $test=0; my ($i,$j,$k,$arg1,$arg2); while(my $argv=shift){ if($test==0){ $arg1=$argv; } if($test>0){ $arg2=$argv; } for($i=1;$i<=$argv;$i++){ if(!($argv%$i)){ if($test==0){ @thing[$i]=$i; } if($test>0){ @thing1[$i]=$i; } } } $test++; } for($j=0;$j<=$arg1;$j++){ for($k=0;$k<=$arg2;$k++){ if(@thing[$j] == @thing1[$k]){ print "A common divisor of $arg1 and $arg2 is: ". @thing[$j] . "\ +n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding the greatest common divisor
by larsen (Parson) on Sep 03, 2001 at 19:01 UTC | |
|
Re: Finding the greatest common divisor
by Dominus (Parson) on Sep 03, 2001 at 21:25 UTC | |
by tilly (Archbishop) on Sep 04, 2001 at 00:09 UTC | |
|
Re: Finding the greatest common divisor
by tachyon (Chancellor) on Sep 03, 2001 at 20:13 UTC | |
|
Re: Finding the greatest common divisor
by damian1301 (Curate) on Sep 03, 2001 at 21:56 UTC | |
|
Re: Finding the greatest common divisor
by George_Sherston (Vicar) on Sep 03, 2001 at 19:05 UTC |