c语言求高手帮忙找一下错!!!
程序如下,错误在最后。#include<stdio.h>floatx1,x2,disc,p,q;greater_than_zero(a,b)floata,b;{x1=(-...
程序如下,错误在最后。
#include<stdio.h>
float x1,x2,disc,p,q;
greater_than_zero(a,b)
float a,b;
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
}
equal_to_zero(a,b)
float a,b;
{
x1=x2=(-b)/(2*a);
}
smaller_than_zero(a,b)
float a,b;
{
p=(-b)/2*a;
q=sqrt(disc)/(2*a);
}
main()
{
float a,b,c;
printf("\n请输入a,b,c,的值:");
scanf("%f %f %f",&a,&b,&c);
printf("方程是%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c);
disc=b*b-4*a*c;
printf("方程的解是:\n");
if(disc>0)
{
greater_than_zero(a,b)
printf("x1=%5.2f,x2=%5.2f\n",x1,x2);
}
else if(disc==0)
{
equal_to_zero(a,b)
printf("x1=%5.2f,x2=%5.2f\n",x1,x2);
}
else
{
smaller_than_zero(a,b)
printf("x1=%5.2f+%5.2fi,x2=%5.2f-%5.2fi\n",p,q,p,q);
}
}
E:\软件\C++\MSDev98\MyProjects\习题八点二\去.cpp(3) : error C2065: 'a' : undeclared identifier
E:\软件\C++\MSDev98\MyProjects\习题八点二\去.cpp(3) : error C2065: 'b' : undeclared identifier
E:\软件\C++\MSDev98\MyProjects\习题八点二\去.cpp(4) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition 展开
#include<stdio.h>
float x1,x2,disc,p,q;
greater_than_zero(a,b)
float a,b;
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
}
equal_to_zero(a,b)
float a,b;
{
x1=x2=(-b)/(2*a);
}
smaller_than_zero(a,b)
float a,b;
{
p=(-b)/2*a;
q=sqrt(disc)/(2*a);
}
main()
{
float a,b,c;
printf("\n请输入a,b,c,的值:");
scanf("%f %f %f",&a,&b,&c);
printf("方程是%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c);
disc=b*b-4*a*c;
printf("方程的解是:\n");
if(disc>0)
{
greater_than_zero(a,b)
printf("x1=%5.2f,x2=%5.2f\n",x1,x2);
}
else if(disc==0)
{
equal_to_zero(a,b)
printf("x1=%5.2f,x2=%5.2f\n",x1,x2);
}
else
{
smaller_than_zero(a,b)
printf("x1=%5.2f+%5.2fi,x2=%5.2f-%5.2fi\n",p,q,p,q);
}
}
E:\软件\C++\MSDev98\MyProjects\习题八点二\去.cpp(3) : error C2065: 'a' : undeclared identifier
E:\软件\C++\MSDev98\MyProjects\习题八点二\去.cpp(3) : error C2065: 'b' : undeclared identifier
E:\软件\C++\MSDev98\MyProjects\习题八点二\去.cpp(4) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询