Thread for loop
(10 answers)
Opened by nano at 2015-04-03 23:46 Guest nano Probier' mal "<=" statt "!=". Dann noch'n paar andere Sachen: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #!/usr/bin/perl use warnings; use strict; print "please enter two odd numbers \n"; print "enter first odd number: "; my $odd1 = <STDIN>; chomp ($odd1); print "enter second odd number: "; my $odd2 = <STDIN>; chomp ($odd2); if ($odd1 % 2 == 0 || $odd2 % 2 == 0) { exit; } my @odds; my $step = 2; if ($odd1 >= $odd2) { $step *= -1; } my $i; for ($i = $odd1; $i <= $odd2;$i += $step) { push(@odds, $i); } print "numbers:"; foreach $i (@odds) { print "$i "; } print "\n"; Last edited: 2015-04-04 01:14:29 +0200 (CEST) |