Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let a = Number(input[0]);
  4. let b = Number(input[1]);
  5. let c = Number(input[2]);
  6.  
  7. let d = ((Math.pow(b, 2)) - (4 * a * c));
  8. let x1 = (-b + Math.sqrt(d)) / (2 * a);
  9. let x2 = (-b - Math.sqrt(d)) / (2 * a);
  10.  
  11. if (d > 0 && x1 < x2) {
  12. console.log(x1 + "\n" + x2);
  13. }
  14. else if (d > 0 && x2 < x1) {
  15. console.log(x2 + "\n" + x1);
  16. }
  17. else if (d == 0) {
  18. console.log(x1);
  19. }
  20. else if (d < 0) {
  21. console.log("no");
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement