电动升降柱:C语言编程的来啊~~~~

来源:百度文库 编辑:高校问答 时间:2024/03/29 21:15:22
我是个初学者啊~~我用软件实践的时候发现不管怎么输入都有错误,我按书上的输入还是不行~~帮我看看这个有什么错误啊?
#include<stdio.h>
#include<math.h>
void main
{float a,b,c,disc,p,q,x1,x2;
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q
x2=p-q
printf("x1=%f,x2=%f",x1,x2);

我晕死啊~~这是抄的潭浩强书上的程序啊~~~......main后的()是打掉了的....其他的是书上的啊....顺便问下那些符号,是数字键上面的,还是智能ABC上V3里面的啊??

问题出在格式化输入吧。你那有","也要输进去的。那是一般的字符,建议你去掉",",或是输入时注意点。

#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,disc,p,q,x1,x2;
scanf("%f%f&f",&a,&b,&c);
disc=b*b-4*a*c;
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q;
x2=p-q;
printf("x1=%f,x2=%f",x1,x2);
}
1.void main(),少()
2.{}&%;全应是英文下的符号
3.printf("x1=%f,x2=%f",x1,x2); 输出时是%不是&
4.scanf("%f%f&f",&a,&b,&c); 把""中的%f后的,去掉,否则只能读入第一个数

注意{&%}全是英文下的符号

1.void main(),少()
2. x1=p+q;x2=p-q;
应该就这些吧
改后结果应该是#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,disc,p,q,x1,x2;
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q;
x2=p-q;
printf("x1=%f,x2=%f",x1,x2);
}
如果调试还是错误的话TC的工作环境设置的问题拉!那个问题就有点复杂拉!你还是用toubor c for windows

#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,disc,p;
double q,x1,x2;
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q ;
x2=p-q ;
printf("x1=%f,x2=%f",x1,x2);
}
1.符号问题,英文模式下%&{}
2.开方后,q的类型应该为double型,若用float会丢失数据,因为q的类型变 了,所以与q有关的x1,x2也需要设成double
3.main后加()
4.x1=p+q,x2=p-q后面应加分号
其他地方无问题

#include<stdio.h>
#include<math.h>
void main()
{
float a, b, c, disc, p, q, x1, x2;
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
p=-b/(2*a);
if (disc >= 0)
{
q=sqrt((disc)/(2*a));
x1=p+q ;
x2=p-q ;
printf("x1 = %.2f, x2 = %.2f",x1,x2);
}
else
{
disc = -disc;
q=sqrt((disc)/(2*a));
printf("x1 = %.2f + %.2fi, x2 = %.2f - %.2fi", p, q, p, q);
}
}

你的错误是不是:
error 目录盘:\\目录文件\目标文件.c4:Size of structure or array not know
error 目录盘:\\目录文件\目标文件.c4:Delaration sytax error
这两个??我刚才运行你的这段程序就是这两个错误。
恩 你这段程序还是有问题 还得在完善才行!!