Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int
- main(void)
- {
- enum
- {
- COEFFICIENT1 = 4,
- TWO_ANSWER = 2
- };
- int a, b, c, ans = 0;
- long long d;
- double x1, x2, sqrt_d;
- scanf("%d%d%d", &a, &b, &c);
- if(a && b && c)
- {
- d = b * 1LL * b - COEFFICIENT1 * 1LL * a * c;
- if (d == 0) {
- ans = 1;
- x1 = (double) -b / (2 * a);
- } else if (d > 0) {
- ans = TWO_ANSWER;
- sqrt_d = sqrt(d);
- x1 = (-b - sqrt_d) / (2 * a);
- x2 = (-b + sqrt_d) / (2 * a);
- }
- } else if (a && b) {
- ans = TWO_ANSWER;
- if(b < 0) {
- x1 = 0;
- x2 = (double) -b / a;
- } else {
- x1 = (double) -b / a;
- x2 = 0;
- }
- } else if (a && c) {
- if(-c * 1LL * a > 0) {
- ans = TWO_ANSWER;
- x1 = -sqrt((double) -c / a);
- x2 = -x1;
- }
- } else if (a) {
- ans = 1;
- x1 = 0;
- } else if (b && c) {
- ans = 1;
- x1 = (double) -b / c;
- } else if (b) {
- ans = 1;
- x1 = 0;
- } else if (c == 0) {
- ans = -1;
- }
- printf("%d", ans);
- if(ans > 0) {
- printf(" %.10lf", x1);
- }
- if(ans > 1) {
- printf(" %.10lf", x2);
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement