How to write a Perl program that adds up the numbers in a file and prints out their sum, average, max and min. There is one number per line. You must print the average out showing two digits after the decimal point.
The numbers are:
50
20
3
4
5
Anthony Cameron
-2
Light Poster
masijade
commented:
Well, ask a stupid question ... We are not a homework service.
-2
nonshatter
commented:
Show some effort
+0
Recommended Answers
Jump to PostOh, upset that nobody did your work for you? Too bad.
Jump to PostI'll do it for you, but I don't think you'll be able to turn it in as your work.
use strict; use warnings; use List::Util qw(sum max min); my @nums=<DATA>; my $sum=sum(@nums); my $avg=$sum/@nums; my $max=max(@nums); my $min=min(@nums); print "Sum: $sum\n"; print "Avg: $avg\n"; print "Min: $min\n"; …
All 6 Replies
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
mitchems
12
Posting Whiz in Training
mitchems
12
Posting Whiz in Training
Anthony Cameron
-2
Light Poster
techieinvents
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.