Sum multiples of 3 and 5: Difference between revisions
no edit summary
(→{{header|Mathematica}}: Marked incorrect.) |
No edit summary |
||
Line 460:
Output for n = 1000: ''233168''.
=={{header|Perl}}==
<lang Perl>#!/usr/bin/perl
use strict ;
use warnings ;
use List::Util qw( sum ) ;
sub sum_3_5 {
my $limit = shift ;
return sum grep { $_ % 3 == 0 || $_ % 5 == 0 } ( 1..$limit - 1 ) ;
}
print "The sum is " . sum_3_5( 1000 ) . " !\n" ;</lang>
{{out}}
<pre>The sum is 233168 !</pre>
=={{header|Perl 6}}==
|