doing first set of exercises
This commit is contained in:
32
cli/exercise_01/c.pl
Normal file
32
cli/exercise_01/c.pl
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Math::Complex;
|
||||
|
||||
|
||||
sub quad {
|
||||
my ($a, $b, $c) = @_;
|
||||
my $positive = (
|
||||
($b * -1) - sqrt(($b ** 2) - (4 * ($a * $c))) / (2 * $a)
|
||||
);
|
||||
my $negative = (
|
||||
($b * -1) + sqrt(($b ** 2) - (4 * ($a * $c))) / (2 * $a)
|
||||
);
|
||||
|
||||
return ($positive, $negative);
|
||||
}
|
||||
|
||||
|
||||
my @xx0 = quad(1, 2, 3);
|
||||
printf("%s, %s\n", $xx0[0], $xx0[1]);
|
||||
|
||||
my @xx1 = quad(4, 5, 6);
|
||||
printf("%s, %s\n", $xx1[0], $xx1[1]);
|
||||
|
||||
my @xx2 = quad(7, 8, 9);
|
||||
printf("%s, %s\n", $xx2[0], $xx2[1]);
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
||||
Reference in New Issue
Block a user