c语言在线等
答案:2 悬赏:40 手机版
解决时间 2021-03-01 23:36
- 提问者网友:谁的错
- 2021-03-01 08:40
c语言在线等
最佳答案
- 五星知识达人网友:胯下狙击手
- 2021-03-01 09:21
//
// Created by Broderick on 2018-04-08.
//
#include "stdio.h"
#include "Math.h"
void swap(double *p, double *q) {
*p = *p + *q - (*q = *p);
}
// ax^2 + bx + c = 0
double *OneQuadraticEquation(double a, double b, double c, double result[2]) {
result[0] = ((-1 * b) + sqrt(pow(b, 2) - 4 * a * c))/( 2 * a);
result[1] = ((-1 * b) - sqrt(pow(b, 2) - 4 * a * c))/( 2 * a);
printf("x1 = %.2d, x2 = %.2d", result[1], result[2]);
if(result[0] > result[1]) {
swap(result, result + 1);
}
return result;
}
int main() {
double a, b, c, result[2];
printf("请用逗号分隔并输入 a, b, c
");
scanf("%d%d%d", a, b, c);
OneQuadraticEquation(a, b, c, result);
return 0;
}
// Created by Broderick on 2018-04-08.
//
#include "stdio.h"
#include "Math.h"
void swap(double *p, double *q) {
*p = *p + *q - (*q = *p);
}
// ax^2 + bx + c = 0
double *OneQuadraticEquation(double a, double b, double c, double result[2]) {
result[0] = ((-1 * b) + sqrt(pow(b, 2) - 4 * a * c))/( 2 * a);
result[1] = ((-1 * b) - sqrt(pow(b, 2) - 4 * a * c))/( 2 * a);
printf("x1 = %.2d, x2 = %.2d", result[1], result[2]);
if(result[0] > result[1]) {
swap(result, result + 1);
}
return result;
}
int main() {
double a, b, c, result[2];
printf("请用逗号分隔并输入 a, b, c
");
scanf("%d%d%d", a, b, c);
OneQuadraticEquation(a, b, c, result);
return 0;
}
全部回答
- 1楼网友:动情书生
- 2021-03-01 09:46
#include
#include
int main(void)
{
double a,b,c,x1,x2,temp;
printf(" 利用公式法计算一元二次方程的解(不作无解判断)。 ");
printf(" 请输入方程系数a、b、c的值(数值之间用空格隔开):");
scanf("%lf %lf %lf",&a,&b,&c);
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
if(x1>=x2)
{
temp=x1;
x1=x2;
x2=temp;
}
printf(" x1 = %.2f x2 = %.2f ",x1,x2);
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯