编程求教1

来源:百度知道 编辑:UC知道 时间:2024/05/03 02:48:29
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
int main()

{
float a,b,c,x,y;
printf("input a b and c:");
if(a==0)
printf("error!");
else
if((b*b-4*a*c)<0)
printf("error!");
else
scanf("%f%f%f",&a,&b,&c);
x=(-b+sqr(b*b-4*a*c))/(2*a);
y=(-b-sqr(b*b-4*a*c))/(2*a);
printf("%f\t%f",x,y);
system("pause");
}
我想求一元二次方程的根,
它为什么说17 C:\Documents and Settings\cs\My Documents\未命名2.cpp `sqr' undeclared (first use this function)
请问该如何解决
拜托您了

# include<stdio.h>
# include<math.h>
main(){
float a,b,c,x,x1,x2,z;
printf("请输入a,b,c:\n");
scanf("%f,%f,%f",&a,&b,&c);
z=b*b-4*a*c;
if (z<0)
{
printf("无解\n");
}
if (z==0)
{
x=(-b)/(2*a);
printf("x = %f\n",x);
}
if (z>0)
{
x1=(-b+(double) sqrt((double) z))/(2*a);
x2=(-b-(double) sqrt((double) z))/(2*a);
printf("x1 = %f; x2 = %f\n",x1,x2) ;
}
getch();
}

这个我写的测试过没有问题了