Skip to content

Instantly share code, notes, and snippets.

@bliz937
Created February 25, 2016 20:53
Show Gist options
  • Save bliz937/406a68645061acb9805d to your computer and use it in GitHub Desktop.
Save bliz937/406a68645061acb9805d to your computer and use it in GitHub Desktop.
My first attempt at perl. e^x
#!/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