[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

simple Perl programs

I am learning the basics of Perl and would like to have some extremely simple beginning programs to do minor computations such as quadratic formula, and possibly something for an easy text-based user interface.  I am in a hurry for this.  Thanks.
0
neymeyer
Asked:
neymeyer
  • 2
1 Solution
 
ozoCommented:
die "linear" if $a == 0;
$m = $b**2 - 4*$a*$c;
if( $m >= 0 ){
  @roots=((-$b + sqrt($m))/(2*$a),(-$b - sqrt($m))/(2*$a));
  print "real roots of $a*x²+$b*x+$c=0: @roots\n";
}else{
  use Math::Complex;
  @roots=map{($b+$_)/(2*$a)}root($m,2);
  print "complex roots of $a*x²+$b*x+$c=0: @roots\n";
}
0
 
neymeyerAuthor Commented:
Thank you
0
 
ozoCommented:
#@roots=map{($b+$_)/(2*$a)}root($m,2); #should have been
@roots=map{(-$b+$_)/(2*$a)}root($m,2);
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now