C语言 程序填空(调用函数f用以求1元2次方程的实根)

来源:百度知道 编辑:UC知道 时间:2024/05/07 20:26:00
以下程序中"____ N ____"是根据程序功能需要填充部分,请完成程序填充(注意:不得加行、减行、加句、减句,否则后果自负)。该程序功能:调用函数f用以求1元2次方程 x*x+5*x-2=0 的实根。
#include <stdio.h>
#include <math.h>
int f(float a,float b,float c,float *x1,float *x2)
{ if(b*b-4*a*c<0) return 1;
*x1=(-b+sqrt(b*b-4*a*c))/2/a;
*x2=(-b-sqrt(b*b-4*a*c))/2/a;
______1______
}
void main()
{ float u1,u2; float a,b,c;
printf("input a b c:");
scanf("%f%f%f",&a,&b,&c);
if(b*b-4*a*c<0) printf("实数范围内无解\n");
else printf("%.2f %.2f\n",u1,u2);
}
上面的有错,这个才是:
以下程序中"____ N ____"是根据程序功能需要填充部分,请完成程序填充(注意:不得加行、减行、加句、减句,否则后果自负)。该程序功能:调用函数f用以求1元2次方程 x*x+5*x-2=0 的实根。
#include <stdio.h>
#include <math.h>
int f(float a,float b,float c,float *x1,float *x2)
{ if(b*b-4*a*c<0) return 1;
*x1=(-b+sqrt(b*b-4*a*c))/2/a;
*x2=(-b-sqrt(b*b-4*a*c))&#

#include <stdio.h>
#include <math.h>
int f(float a,float b,float c,float *x1,float *x2)
{ if(b*b-4*a*c<0) return 1;
*x1=(-b+sqrt(b*b-4*a*c))/2/a;
*x2=(-b-sqrt(b*b-4*a*c))/2/a;
return 0; //1
}
void main()
{ float u1,u2; float a,b,c;
printf("input a b c:");
scanf("%f%f%f",&a,&b,&c);
if(f(a,b,c,&u1,&u2)) printf("实数范围内无解\n"); //2
else printf("%.2f %.2f\n",u1,u2);
}

1、return 0;
2、f(a,b,c,&u1,&u2)