请直接传代码,不然不好看,用 Markdown 的个式插入代码。或者点击插入代码后直接粘贴。不然实在难看。
肉眼看出问题如下
m
和n
并没有被赋过值而被直接使用会导致 m
和 n
在使用时会产生不可预测的结果。我根据你的代码 推测出你是需要求可能是 求二次方程的根:
代码如下 望采纳!
#include <stdio.h>
#include <math.h>
void add(double a,double b,double c,double *m,double *n);
int main(){
double a,b,c,m,n;
printf("请依次输入a b c用空格隔开");
scanf("%lf%lf%lf",&a,&b,&c);
double delt = b * b - 4*a*c;
if( delt > 0 ){
add(a,b,c,&m,&n);
printf("方程有两个不相等的实数根 : %g , %g",m,n);
} else if( delt == 0 ){
printf("方程有一个实数根 : %g ",(-b + sqrt(delt)) / (2 * a) );
} else {
printf("方程没有实数根");
}
}
void add(double a,double b,double c, double *m ,double *n){
*m = (-b + sqrt(b * b - 4*a*c)) / (2 * a) ;
*n = (-b - sqrt(b * b - 4*a*c)) / (2 * a) ;
}