shabird has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks, I have wrote a program that stores five numbers in different variables and then calculates the sum of these numbers. Thereafter, it divides each number with the sum and store these in an array. Last, it prints out the entire array to the terminal. I just want to ask is this the good approach which i used? please have a look at my code below
#!/usr/bin/perl -w use warnings; use strict; my $num1 = 5; my $num2 = 10; my $num3 = 15; my $num4 = 20; my $num5 = 25; my $totalSum = $num1 + $num2 + $num3 + $num4 + $num5; my @array = ($num1/$totalSum, $num2/$totalSum, $num3/$totalSum, $num4/ +$totalSum, $num5/$totalSum); print "The required numbers are: @array";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Finding sum of numbers and storing it an Array
by tobyink (Canon) on Sep 21, 2020 at 09:11 UTC | |
by shabird (Sexton) on Sep 21, 2020 at 09:32 UTC | |
by tobyink (Canon) on Sep 21, 2020 at 11:03 UTC | |
by hippo (Bishop) on Sep 21, 2020 at 09:45 UTC | |
by shabird (Sexton) on Sep 21, 2020 at 09:51 UTC | |
by choroba (Cardinal) on Sep 21, 2020 at 10:10 UTC | |
Re: Finding sum of numbers and storing it an Array
by hippo (Bishop) on Sep 21, 2020 at 09:20 UTC | |
Re: Finding sum of numbers and storing it an Array
by BillKSmith (Monsignor) on Sep 21, 2020 at 14:02 UTC | |
Re: Finding sum of numbers and storing it an Array
by tybalt89 (Monsignor) on Sep 21, 2020 at 11:09 UTC |
Back to
Seekers of Perl Wisdom