Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- const double eps = 1e-9;
- inline int fcompare(double a, double b)
- {
- return fabs(a - b) < eps ? 0 : a < b ? -1 : 1;
- }
- int main()
- {
- double a, b, c;
- system("chcp 1251 > nul");
- while (1)
- {
- printf("Введите коэффициенты квадратного уравнения a, b и c:\n");
- scanf("%lf%lf%lf", &a, &b, &c);
- if (fcompare(a, 0.0)) // a != 0.0
- {
- int res_cmp;
- double d;
- d = b*b - 4.0*a*c;
- res_cmp = fcompare(d, 0.0);
- if (res_cmp == 0) // d == 0
- {
- printf("x = %lf\n", -b / (a + a));
- }
- else if (res_cmp > 0) // d > 0.0
- {
- printf("x1 = %lf\n", -(b + sqrt(d)) / (a + a));
- printf("x2 = %lf\n", -(b - sqrt(d)) / (a + a));
- }
- else // d < 0.0
- {
- printf("Корней на множестве действительных чисел нет.\n");
- }
- }
- printf("\n");
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement