新手上路初学C,大家看看这个程序哪里错了

来源:百度知道 编辑:UC知道 时间:2024/06/05 03:03:14
#include "stdio.h"
#include "math.h"
main()
{
float a,b,c,a1,a2
printf("ax^+bx+c=0,please input the value of a,b and c,ensure a is not 0");
getch();
scanf("%f,%f,%f\n",&a,&b,&c);
if (b*b-4*a*c<0) printf("no answer\n");
else a1=(-b+sqrt(b*b-4*a*c))/(2*a);
a2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("%f,%f\n",a1,a2) ;
}

这是个一元二次方程求解的程序
报错显示:c6:declaration syntax error in function main

scan后面的\n去掉就完全可以解决了,怎么一个问题问了这么多便

#include "stdio.h"
#include "math.h"
main()
{
float a,b,c,a1,a2 //少“;”
printf("ax^+bx+c=0,please input the value of a,b and c,ensure a is not 0");
getch(); //可能是 getchar();
scanf("%f,%f,%f\n",&a,&b,&c);
if (b*b-4*a*c<0) printf("no answer\n");
else a1=(-b+sqrt(b*b-4*a*c))/(2*a);
a2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("%f,%f\n",a1,a2) ; //";"改成";"
}

#include "stdio.h"
#include "math.h"
main()
{
float a,b,c,a1,a2
printf("ax^+bx+c=0,please input the value of a,b and c,ensure a is not 0");
getch();
scanf("%f,%f,%f\n",&a,&b,&c);
if (b*b-4*a*c<0) printf("no answer\n");
else a1=(-b+sqrt(b*b-4*a*c))/(2*a);
a2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("%f,%f\n&qu