Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl -w
    
    ...
    $sum += $_ for 1 .. $n;
    
    print "$sum\n";
    
  2. or download this
    Sum(1..n) = n(n+1)/2
    
  3. or download this
    #!/usr/bin/perl -w
    
    ...
    my $sum = $n * ( $n + 1 ) / 2;
    
    print "$sum\n";