2个回答
展开全部
只会写perl,纯手打呀。。。
#!/usr/bin/perl
use strict;
print("input x=");
chomp(my $x = <>);
die ("error ,only natural number permitted \n") if($x !~ /\d+/ or $x <= 0);
print("input n=");
chomp(my $n = <>);
die ("error , only natural number permitted\n") if($n !~ /\d+/ or $n <= 0);
my $result = 1;
for (my $i = 1;$i <=$n;$i++)
{
my $denominator = 1;
my $factor = $i % 2 == 0 ? 1 : -1;
for(my $j = 1;$j<=$i;$j++) {$denominator *= $j;}
$result += $factor * ($x**$i) / $denominator;
}
print("result is $result\n");
#!/usr/bin/perl
use strict;
print("input x=");
chomp(my $x = <>);
die ("error ,only natural number permitted \n") if($x !~ /\d+/ or $x <= 0);
print("input n=");
chomp(my $n = <>);
die ("error , only natural number permitted\n") if($n !~ /\d+/ or $n <= 0);
my $result = 1;
for (my $i = 1;$i <=$n;$i++)
{
my $denominator = 1;
my $factor = $i % 2 == 0 ? 1 : -1;
for(my $j = 1;$j<=$i;$j++) {$denominator *= $j;}
$result += $factor * ($x**$i) / $denominator;
}
print("result is $result\n");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询