doing first set of exercises
This commit is contained in:
parent
e4d44963fa
commit
c695765b4e
10
cli/exercise_01/a.pl
Normal file
10
cli/exercise_01/a.pl
Normal file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
print "Hello world\n";
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
30
cli/exercise_01/b.pl
Normal file
30
cli/exercise_01/b.pl
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
my $num = 4000 / 7;
|
||||
print "$num\n";
|
||||
|
||||
print int($num + 0.005) . "\n";
|
||||
|
||||
printf("%.3f\n", $num);
|
||||
|
||||
printf("00%.3f\n", $num);
|
||||
|
||||
|
||||
sub show_signed {
|
||||
my ($num) = @_;
|
||||
if ($num gt 0) {
|
||||
printf("+%.3f\n", $num);
|
||||
} else {
|
||||
printf("%.3f\n", $num);
|
||||
}
|
||||
}
|
||||
|
||||
show_signed($num);
|
||||
show_signed($num - 1000);
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
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__
|
40
cli/exercise_01/d.pl
Normal file
40
cli/exercise_01/d.pl
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Math::Complex;
|
||||
|
||||
|
||||
print "Entrez-vous\n";
|
||||
|
||||
my ($a, $b, $c) = (rand(100), rand(100), rand(100));
|
||||
|
||||
print "\$a=$a\n";
|
||||
print "\$b=$b\n";
|
||||
print "\$c=$c\n";
|
||||
|
||||
|
||||
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 @result = quad($a, $b, $c);
|
||||
printf("%s, %s\n", $result[0], $result[1]);
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
Loading…
Reference in New Issue
Block a user