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";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.