10分求助!
查看原帖
10分求助!
1251905
cao_20115楼主2024/1/3 21:39

不知道为什么,只有十分

#include <cstdio>
#include <cmath>
using namespace std;
void swap(double &a, double &b) {
    double c;
    c = a;
    a = b;
    b = c;
}
int main(){
    double a,b,c;
    double x1,x2;
    double flag;
    scanf("%lf %lf %lf", &a, &b, &c);
    flag = b*b - 4*a*c;
    x1 = 1.0 * (-b+sqrt(flag)) / (2 * a);
    x2 = 1.0 * (-b-sqrt(flag)) / (2 * a);
    if(flag < 0) {
        printf("No answer!");
    } else if(flag == 0) {
        x1 = -b / (2 * a);
        printf("x1=x2=%.5lf", x1);
    } else {
        if(x1 > x2) {
            swap(x1,x2);
        }
        printf("x1=%.5lf;x2=%.5lf", x1, x2);
    }
    return 0;
}
2024/1/3 21:39
加载中...