C语言 菜 求助

来源:百度知道 编辑:UC知道 时间:2024/05/26 09:35:07
#include<stdio.h>
void main()
{ float s=0;
int a=1,b=2,c=1;
for(c<=20;c++);
{
s=s+b/a;
a=b;
b=b+a;
}
printf("s=%lf",&s)

看看什么问题

warning C4552: '<=' : operator has no effect; expected operator with side-effect

error C2143: syntax error : missing ';' before ')'

fatal error C1004: unexpected end of file found

void main()
{ float s=0;
int a=1,b=2,c=1;
for(;c<=20;c++)
{
s=s+b/a;
a=b;
b=b+a;
}
printf("s=%lf",s)

}
这样应该可以了吧

for(表达式1;表达式2;表达式3)
{
循环体;
}
这是for()循环的结构,其中表达式可以不写,但是“;”一定要要有。还有for(表达式1;表达式2;表达式3)后面不要加“;”,如果加了那么for()循环就只执行到分号那,下面的就不属于for()循环了。