fork download
  1. #!/usr/bin/perl
  2. #
  3. # Calculation the roots of a quadratic equation
  4. #
  5. # a*x^2 + b*x + c = 0
  6. #
  7. # # # # # # # # # # # # # # # # # # # # # # # #
  8. #
  9. # Задача :
  10. # - Расчет Корней Квадратного Уравнения
  11. # Решение :
  12. # - автор Дмитрий Кузнецов
  13. # - цена $108.17
  14. #
  15. # # # # # # # # # # # # # # # # # # # # # # # #
  16. #
  17. #
  18.  
  19. my $a = <STDIN>;
  20. my $b = <STDIN>;
  21. my $c = <STDIN>;
  22.  
  23. # Formula for eauation of discriminator
  24. my $d = sqrt($b*$b - 4*$a*$c);
  25.  
  26. # Roots
  27. my $x1 = (-$b - $d) / (2 * $a);
  28. my $x2 = (-$b + $d) / (2 * $a);
  29.  
  30. # Output Results
  31. print ("Roots for ... a*x^2 + b*x + c = 0 \n");
  32. print (" a = $a b = $b c = $c \n :: x1 : $x1 :: x2 : $x2 ::\n");
  33.  
  34.  
Success #stdin #stdout 0.01s 5308KB
stdin
1
-1
0
stdout
Roots for ... a*x^2 + b*x + c = 0 
 a = 1
 b = -1
 c = 0
 
 :: x1 : 0 :: x2 : 1 ::