Created
April 13, 2019 00:54
-
-
Save tomcha/df1e478bb7d6111cf84d06c98ece4d3f to your computer and use it in GitHub Desktop.
最大公約数をユークリッドの互除法を使って再帰で実装する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature 'say'; | |
use DDP { deparse => 1 }; | |
print "整数2つを入力して下さい i,j >>"; | |
chomp(my $input = <STDIN>); | |
my ($i, $j) = split(/,/, $input); | |
say get_gcd($i, $j); | |
sub get_gcd{ | |
my $x = shift; | |
my $y = shift; | |
my $mod = $x % $y; | |
my $result; | |
if ($mod == 0){ | |
return $y; | |
} else { | |
return get_gcd($y, $mod); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment