会c语言的帮忙看一下

来源:百度知道 编辑:UC知道 时间:2024/08/23 12:25:32
初学c语言,语法还没弄清楚,试着写了一个小程序,但提示编译失败,大家帮忙看一下
加for语句是为了让程序多运行几次

/* 求二次方程的根*/

#include "stdio.h"
#include "conio.h"

main()
{
int l;
for(l=0;l<100;l++)
{
float a,b,c,da,x1,x2;
printf("input a b and c");
scanf("%f%f%f",&a,&b,&c);
da=b*b-4*a*c
if(da>0)
{
x1=(-1*b+sqrt(da))/(2*a);
x2=(-1*b-sqrt(da))/(2*a);
printf("x1=%f",x1);
printf("x2=%f",x2);
else if(da==0)
{
x1=(-1*b)/(2*a);
printf("zhi you yi ge geng %f",x1);
}
else
{
printf("geng bu cun zai");
}
}
}

getch();
}

#include "stdio.h"
#include "conio.h"
#include "math.h"
main() {
float a,b,c,da,x1,x2;
int i;
for(i=0;i<10;i++){
scanf("%f%f%f",&a,&b,&c);
da=b*b-4*a*c ;
if(da>0) {
x1=(-1*b+sqrt(da))/(2*a);
x2=(-1*b-sqrt(da))/(2*a);
printf("x1=%f",x1);
printf("x2=%f",x2);
}
else if(da==0) {
x1=(-1*b)/(2*a);
printf("zhi you yi ge geng %f",x1);
}
else {
printf("geng bu cun zai");
}
}
getch();
}

咱也是初学者 所以没看懂

sqrt是在math头文件中的,所以要加上
#include<math.h>

da=b*b-4*a*c //这句后面少一个 ; 号。

建议使用visual studio 2008版 具有详细的错误提示

第一:da=b*b-4*a*c //这句后面少一个 ; 号。
第二:if语句的回括号跟错地方了,应在else if 以前

#include "stdio.h"
#include "conio.h"
main()
{
int l;
float a,b,c,da,x1,x2;
for(l=0;l<100;