作业帮 > 综合 > 作业

帮忙检查一下c语言的程序错在哪里,题目是求解一元二次方程.a*x*x+b*x+c=0

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/06/01 10:12:13
帮忙检查一下c语言的程序错在哪里,题目是求解一元二次方程.a*x*x+b*x+c=0
题目是求解一元二次方程.a*x*x+b*x+c=0
# include
# include
float x1,x2,disc,p,q;
greater_than_zero(float a,float b)
{x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
}
equal_to_zero(float a,float b)
{
x1=x2=(-b)/(2*a);
}
smaller_than_zero(float a,float b)
{
p=-b/(2*a) ;
q=sqrt(disc)/(2*a);
}
void main ( )
{
float a,b,c;
printf("\nInput a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
printf("\nequation:%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c);
disc=b*b-4*a*c;
printf("root:\n");
if (disc>1e-6)
{
greater_than_zero(a,b);
printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2);
}
else if (fabs(disc)
帮忙检查一下c语言的程序错在哪里,题目是求解一元二次方程.a*x*x+b*x+c=0
1、从函数前要加void
2、getch()函数要包含在头文件中
别的没什么错误.
以下是我自己的程序,由于我写的内容多,所以包含了过多的头文件,你这个问题可以很好的解决.
#include "stdio.h"
#include "string.h"
#include
#include
#include
using namespace std;
float x1,x2,disc,p,q;
void greater_than_zero(float a,float b)
{
x1 = (-b + sqrt(disc))/(2*a);
x2 = (-b - sqrt(disc))/(2*a);
}
void equal_to_zero(float a,float b)
{
x1 = (-b)/(2*a);
x2 = x1;
}
void smaller_than_zero(float a,float b)
{
p = (-b)/(2*a) ;
q = sqrt(disc)/(2*a);
}
void main ( )
{
float a,b,c;
printf("\nInput a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
printf("\nequation:%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c);
disc=b*b-4*a*c;
printf("root:\n");
if (disc>1e-6)
{
greater_than_zero(a,b);
printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2);
}
else if (fabs(disc)