Created
February 25, 2016 20:53
-
-
Save bliz937/406a68645061acb9805d to your computer and use it in GitHub Desktop.
My first attempt at perl. e^x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
sub calc { | |
my $total = 1; | |
my $ans = 10.0; | |
my $x = $_[0]; | |
my $fac = 1.0; | |
my $count = 2; | |
while($ans > 0.00000000001){ | |
$ans = $x/$fac; | |
$total += $ans; | |
$x *= $_[0]; | |
$fac *= $count++; | |
} | |
return $total; | |
} | |
print "e^ "; | |
my $inp = <STDIN>; | |
my $ans = calc($inp); | |
print "e^x = $ans\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment