新手,一元二次方程 functionz中,变量undeclear,且输出结果错误
double getnum(int i, int j, int k){
delta = j*j - 4*i*k;
if(delta > 0)
{
x1 = (-b + sqrt(delta))/(2 * a);
x2 = (-b - sqrt(delta))/(2 * a);
printf("该一元二次方程有两个解,x1 = %f,x2 = %f\n",x1, x2);
}
else if(delta == 0)
{
x1 = (-b)/(2*a);
x2 = x1;
printf("该一元二次方程有一个解,x1=x2=%f\n",x1 ,x2);
}
else
{
printf("该一元二次方程无解\n");
}
}
int main(void)
{
double delta;
double x1;
double x2;
int a,b,c;
printf("请输入a的值: \n");
scanf("%d",&a);
printf("请输入b的值: \n");
scanf("%d",&b);
printf("请输入c的值: \n");
scanf("%d",&c);
getnum(a,b,c);
return 0;
}
/*在code::blocks 16.01 中
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|8|error: 'delta' undeclared (first use in this function)|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|13|error: 'x1' undeclared (first use in this function)|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|13|error: 'b' undeclared (first use in this function)|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|13|error: 'a' undeclared (first use in this function)|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|14|error: 'x2' undeclared (first use in this function)|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|27|warning: 'return' with no value, in function returning non-void [-Wreturn-type]|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|35|warning: unused variable 'x2' [-Wunused-variable]|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|34|warning: unused variable 'x1' [-Wunused-variable]|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|33|warning: unused variable 'delta' [-Wunused-variable]|
C:\Users\xujiang\Desktop\ccccccc\一元二次方程\main.c|28|warning: control reaches end of non-void function [-Wreturn-type]|
*/