Blob


1 #!/usr/bin/perl
3 # Write a program that computes the circumference of a circle with a radius of
4 # 12.5. Circumference is 2π times the radius (approximately 2 times
5 # 3.141592654). The answer you get should be about 78.5.
6 #
7 # Modify the program from the previous exercise to prompt for and accept a
8 # radius from the person running the program. So, if the user enters 12.5 for
9 # the radius, she should get the same number as in the previous exercise.
10 #
11 # Modify the program from the previous exercise so that, if the user enters a
12 # number less than zero, the reported circumference will be zero, rather than
13 # negative.
15 use warnings;
16 use strict;
17 use utf8;
19 sub circum {
20 my $π = 3.141592654;
21 my ($radius) = @_;
22 if ($radius < 0) {
23 return 0;
24 }
25 return 2*$π*$radius;
26 }
28 print "Radius: ";
30 chomp(my $radius = <STDIN>);
32 print "circumference = " . circum($radius) . "\n";