keil中编译错误,为什么呢?

#include<math.h>
#include<stdio.h>
#include<reg51.h>
void main(void)
{
SCON=0x52;
TMOD=0x20;
TH1=0xf3;
TR1=1;
float x;
float y;
for(x=-1.0;x<=1.0;x+=0.1)
{
y=acos(x);
printf("ACOS(%f)=%f\n",x,y);
getchar();
}
}

TEXT.C(18): error C141: syntax error near 'float'
TEXT.C(18): error C202: 'x': undefined identifier
TEXT.C(19): error C141: syntax error near 'float'
TEXT.C(19): error C202: 'y': undefined identifier
TEXT.C(20): error C202: 'x': undefined identifier
TEXT.C(22): error C202: 'y': undefined identifier
TEXT.C(23): error C202: 'x': undefined identifier

你这C语言的基础有点薄弱啊,出错是因为C语言规定,在函数体内,变量定义语句应该在最前边,结果你给放在中间了. 正确的写法如下:
#include<math.h>
#include<stdio.h>
#include<reg51.h>
void main(void)
{
float x;
float y;
SCON=0x52;
TMOD=0x20;
TH1=0xf3;
TR1=1;

for(x=-1.0;x<=1.0;x+=0.1)
{
y=acos(x);
printf("ACOS(%f)=%f\n",x,y);
getchar();
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-03-19
你这C语言的基础有点薄弱啊,出错是因为C语言规定,在函数体内,变量定义语句应该在最前边,结果你给放在中间了.
正确的写法如下:
#include<math.h>
#include<stdio.h>
#include<reg51.h>
void
main(void)
{
float
x;
float
y;
SCON=0x52;
TMOD=0x20;
TH1=0xf3;
TR1=1;
for(x=-1.0;x<=1.0;x+=0.1)
{
y=acos(x);
printf("ACOS(%f)=%f\n",x,y);
getchar();
}
}
第2个回答  2010-04-17
是不是从哪拷来的程序,可以试试自己重新手写一下出错的几句。外来程序有时有一些肉眼看不到的格式符号,编译器不认。
第3个回答  2010-04-17
估计效率十分够呛!用51来处理浮点数效率不是一般的低,
你要清楚,51是典型的8位单片机!
第4个回答  2010-04-17
变量定义要定义在函数体前

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网