Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub sum_of_even {
- my ($start, $end) = @_;
- my $sum = 0;
- for my $num ($start..$end) {
- $sum += $num if $num % 2 == 0;
- }
- return $sum;
- }
- print "Masukkan rentang bilangan (misalnya 1 10): ";
- my $input = <STDIN>;
- chomp($input);
- my ($start, $end) = split(' ', $input);
- my $result = sum_of_even($start, $end);
- print "Jumlah bilangan genap dari $start hingga $end adalah $result\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement