|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
//系统自带源代码
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
double a, b, c;
if (x1 < x2) {
swap(x1, x2);
}
cin >> a >> b >> c;
double delta = b * b - 4 * a * c;
double x1 = (-b + sqrt(delta)) / (2 * a);
double x2 = (-b - sqrt(delta)) / (2 * a);
cout << fixed << setprecision(2)<<x1 << " "
<< fixed << setprecision(2)<<x2<< endl;
return 0;
}
//本人自己写的源代码
#include<stdio.h>
#include<math.h>
int main(void)
{
float x1, x2,p;
int a, b, c;
scanf_s("%d %d %d",&a,& b,& c);
p = b*b - 4 * a * c;
if (p >= 0)
{
x1 = (-b + sqrt(p)) / (2*a);
x2 = (-b - sqrt(p)) / (2*a);
printf("%.2f %.2f", x1, x2);
}
else
printf("误解");
return 0;
}
//网上找的源代码+修改后
#include<stdio.h>
#include<math.h>
int main(void)
{
int a;
int b;
int c;
double delta;
double x1;
double x2;
scanf_s("%d %d %d",&a,& b,& c);
delta = b * b - 4 * a * c;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2 * a);
x2 = (-b - sqrt(delta)) / (2 * a);
printf("x1 = %.2f, x2 = %.2f\n", x1, x2);
}
else if (delta == 0)
{
x1 = (-b + sqrt(delta)) / (2.0 * a);
x2 = x1;
printf("x1 = x2 = %f\n", x1);
}
else
{
printf("无解\n");
}
return 0;
} |
|