Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main ()
  5. {
  6. FILE *fp, *fo;
  7. fo = fopen("input.txt","r");
  8. fp = fopen("output.txt","w");
  9. double a, b, c, D, x1, x2;
  10. fscanf(fo, "%lf %lf %lf", &a, &b, &c);
  11. D = (pow(b, 2) - 4*a*c);
  12. if (a != 0)
  13. {
  14. if (D < 0)
  15. {
  16. fprintf(fp, "NO");
  17. }
  18. else
  19. {
  20. if (D == 0)
  21. {
  22. fprintf(fp, "%lg", -b / (2*a));
  23. }
  24. else
  25. {
  26. x1 = (-b - sqrt(D))/(2 * a);
  27. x2 = (-b + sqrt(D))/(2 * a);
  28. if (x1 > x2)
  29. {
  30. fprintf(fp, "%lg %lg", x2, x1);
  31. }
  32. else
  33. {
  34. fprintf(fp, "%lg %lg", x1, x2);
  35. }
  36. }
  37. }
  38. }
  39. else
  40. {
  41. if (b == 0)
  42. {
  43. if (c == 0)
  44. {
  45. fprintf(fp, "R");
  46. }
  47. else
  48. {
  49. fprintf(fp, "NO");
  50. }
  51. }
  52. else
  53. {
  54. fprintf(fp, "%lg", -c / b);
  55. }
  56. }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement