Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 having an uproarious good time at the Monastery: (4)
As of 2021-04-18 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?