c语言函数(求方程a乘x平方加b乘x加c等于0的根.要求用三个函数分别计算复数根,两个不同实数根
答案:1 悬赏:0 手机版
解决时间 2021-04-06 12:59
- 提问者网友:缘字诀
- 2021-04-05 21:11
c语言函数(求方程a乘x平方加b乘x加c等于0的根.要求用三个函数分别计算复数根,两个不同实数根
最佳答案
- 五星知识达人网友:煞尾
- 2021-04-05 22:06
#include
#include
void main(){
double a=0, b=0, c=0;
double result_1, result_2, inscriber;
printf("请输入a,b,c\n");
scanf_s("%lf %lf %lf", &a, &b, &c);
if (b*b - 4 * a*c > 0){
result_1 = (-b + sqrt(b*b - 4.0 * a*c)) / (2.0*a);
result_2 = (-b - sqrt(b*b - 4.0 * a*c)) / (2.0*a);
printf("%lf %lf\n", result_1, result_2);
}
else if (b*b - 4 * a*c == 0){
result_1 = (-b) / (2.0*a);
printf("%lf\n", result_1);
}
else if (b*b - 4 * a*c < 0){
result_1 = (-b) / (2.0*a);
inscriber = sqrt(-(b*b - 4.0*a*c)) / (2.0*a);
printf("%lf+%lfi %lf+%lfi\n", result_1, inscriber, result_1, -inscriber);
}
}
#include
void main(){
double a=0, b=0, c=0;
double result_1, result_2, inscriber;
printf("请输入a,b,c\n");
scanf_s("%lf %lf %lf", &a, &b, &c);
if (b*b - 4 * a*c > 0){
result_1 = (-b + sqrt(b*b - 4.0 * a*c)) / (2.0*a);
result_2 = (-b - sqrt(b*b - 4.0 * a*c)) / (2.0*a);
printf("%lf %lf\n", result_1, result_2);
}
else if (b*b - 4 * a*c == 0){
result_1 = (-b) / (2.0*a);
printf("%lf\n", result_1);
}
else if (b*b - 4 * a*c < 0){
result_1 = (-b) / (2.0*a);
inscriber = sqrt(-(b*b - 4.0*a*c)) / (2.0*a);
printf("%lf+%lfi %lf+%lfi\n", result_1, inscriber, result_1, -inscriber);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯