Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. program quadraticeq;
  2. uses crt;
  3. var
  4. a,b,c,x1,x2,R1,I1,R2,I2,D: integer;
  5. p:1..4;
  6. begin
  7. writeln (output, 'Enter a,b i c:'); {ax^2 + bx + c = 0}
  8. readln (a,b,c);
  9.  
  10. D:=sqr(b)-4*a*c; {discriminant}
  11.  
  12. if a=0 then
  13. p:=1
  14. else
  15. if D=0 then begin
  16. p:=2;
  17. x1:=(-b)/(2*a);
  18. end
  19. else
  20. if D>0 then begin
  21. p:=3;
  22. x1:=(-b+sqrt(D))/(2*a);
  23. x2:=(-b-sqrt(D))/(2*a);
  24. end
  25. else begin
  26. p:=4;
  27. R1:=(-b)/(2*a);
  28. I1:=sqrt(-D)/(2*a);
  29. R2:=-R1;
  30. I2:=-I1;
  31. end;
  32.  
  33. case p of
  34. 1: writeln (output, 'Wrong entry! Quantificator a mustnt be zero!');
  35. 2: writeln (output, 'Double root of the equation is: x1=x2=',x1);
  36. 3: writeln (output, 'Roots of the equation are x1=',x1,'and x2=',x2,'.');
  37. 4: writeln (output, 'Complex roots of the equation are x1=',R1,'+i',I1,' and x2=',R2,'+i',I2,'.');
  38. end;
  39. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement