C语言编程问题求解答

img

#include<stdio.h>
#include<math.h>
int main() {
    double a, b, c, d, x1, x2;
    scanf("%lf %lf %lf", &a, &b, &c);
    d =  b * b - 4 * a * c;
    if(d == 0) {
        x1 = (-b) / (2 * a);
        printf("x1=x2=%.5lf", x1);
    } else if(d > 0) {
        x1 = (-b + sqrt(d)) / (2 * a);
        x2 = (-b - sqrt(d)) / (2 * a);
        printf("x1=%.5lf;x2=%.5lf", x1,x2);
    } else {
        printf("no solution");
    }
    return 0;
}

#include <stdio.h>
#include <math.h>
int main()
{
    double disc, a, b, c, p, q, x1, x2;
    scanf("%lf %lf %lf", &a, &b, &c);
    disc = b * b - 4 * a * c;
    if (disc < 0)
        printf("no solution\n");
    else
    {
        p = (-b) / (2 * a);
        q = sqrt(disc) / (2 * a);
        x1 = p + q;
        x2 = p - q;
        if(x1 == x2){
            printf("x1=x2=%.5f", x1);
        }else{
            if(x1 > x2){
                printf("x1=%.5f;x2=%.5f\n", x1, x2);
            }else{
                printf("x1=%.5f;x2=%.5f\n", x2, x1);
            }
        }
    }
    return 0;
}