Calculator for Quadratic Equations


SUBMITTED BY: uuuuuu

DATE: Oct. 24, 2016, 7:11 p.m.

FORMAT: Text only

SIZE: 1.1 kB

HITS: 625

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. int main()
  5. {
  6. printf("Calculator for Quadratic Equations.Please enter values for a, b and c. \n");
  7. float a, b, c;
  8. float x1, x2, d;
  9. printf("Enter a = ");
  10. scanf("%g", &a);
  11. printf("Enter b = ");
  12. scanf("%g", &b);
  13. printf("Enter c = ");
  14. scanf("%g", &c);
  15. if (a == 0)
  16. {
  17. x1 = - c / b;
  18. printf("x1 = %g\n", x1);
  19. }
  20. else if (b == 0)
  21. {
  22. if (-c / a < 0)
  23. {
  24. printf("Nqma reshenie\n");
  25. }
  26. else
  27. {
  28. x1 = sqrt(-c / a);
  29. x2 = -1 * sqrt(-c / a);
  30. printf("x1 = %g\n", x1);
  31. printf("x2 = %g\n", x2);
  32. }
  33. }
  34. else if (c == 0)
  35. {
  36. x1 = 0;
  37. x2 = -b / a;
  38. printf("x1 = %g\n", x1);
  39. printf("x2 = %g\n", x2);
  40. }
  41. else
  42. {
  43. d = b*b - 4 * a*c;
  44. if (d < 0)
  45. {
  46. printf("Nqma realni koreni\n");
  47. }
  48. else if (d == 0)
  49. {
  50. x1 = (-b) / (2 * a);
  51. printf("x1 = x2 = %g\n", x1);
  52. }
  53. else
  54. {
  55. x1 = (-b + sqrt(d)) / (2 * a);
  56. x2 = (-b - sqrt(d)) / (2 * a);
  57. printf("x1 = %g\n", x1);
  58. printf("x2 = %g\n", x2);
  59. }
  60. }
  61. system("PAUSE");
  62. return 0;
  63. }

comments powered by Disqus