Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Finding sum of numbers and storing it an Array

by tybalt89 (Prior)
on Sep 21, 2020 at 11:09 UTC ( #11121995=note: print w/replies, xml ) Need Help??


in reply to Finding sum of numbers and storing it an Array

With minimal editing...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11121986 use warnings; my @numbers = ( my $num1 = 5, my $num2 = 10, my $num3 = 15, my $num4 = 20, my $num5 = 25, ); my $totalSum = 0; $totalSum += $_ for @numbers; $_ /= $totalSum for my @array = @numbers; # just to confuse your t +eacher print "The required numbers are: @array\n";

Outputs:

The required numbers are: 0.0666666666666667 0.133333333333333 0.2 0.2 +66666666666667 0.333333333333333

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11121995]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2020-10-20 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (210 votes). Check out past polls.

    Notices?