diff options
| -rw-r--r-- | challenge-090/cristian-heredia/perl/ch-2.pl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-090/cristian-heredia/perl/ch-2.pl b/challenge-090/cristian-heredia/perl/ch-2.pl new file mode 100644 index 0000000000..2aeac8b209 --- /dev/null +++ b/challenge-090/cristian-heredia/perl/ch-2.pl @@ -0,0 +1,38 @@ +=begin + + TASK #2 › Ethiopian Multiplication + Submitted by: Mohammad S Anwar + You are given two positive numbers $A and $B. + + Write a script to demonstrate Ethiopian Multiplication using the given numbers. + +=end +=cut + +use strict; +use warnings; + +#variables: +my $A = 14; +my $B = 12; +my $result = 0; +print "The result for $A * $B is: "; +calculation(); + +sub calculation { + checkOdd($A); + while ($A != 1) { + use integer; + $A = $A/2; + $B = $B*2; + checkOdd($A); + } + print "$result\n"; +} + +sub checkOdd { + my $number = shift; + if ($number%2) { + $result = $result + $B; + } +}
\ No newline at end of file |
