The objective of
the program is to calculate an average
for any two given numbers. Here, to begin with store the desired numbers
for which averages are to be determined in scalar variables ($a, $b, $c, etc). Add
any two numbers using the scalar variables and divide them by 2. The result of
the calculation is stored in another scalar variable ($avg1, $avg2, $avg3,
etc). Once the results are obtained and stored, we need to print the result on
the screen. For this purpose we have a command called “print”. The print command also includes some special
commands such as “\n”, “\t” for new line and tab respectively. These commands
are optional.
- #calculate averages for the following
pairs:
- $a=12;
- $b=13;
- $c=14;
- $d=15;
- $e=16;
- $f=17;
- $avg1 = ($a+$b)/2;
- $avg2 = ($c+$d)/2;
- $avg3 = ($e+$f)/2;
- $avg4 = ($b+$c)/2;
- print
"$avg1\n$avg2\n$avg3\n$avg4\n"
RESULTS:
12.5
14.5
16.5
13.5