main()
{
int i,sum;
sum=0;
for(i=0;i<=100;)
{
sum=sum+i;
i=i+2;
}
printf("sum=",sum);
}
直接编译就OK,祝你成功!
solution
1
#
include
int
main
()
{
int
i,sum=0;
for
(i=1;i<=100;++i)
{
if
(i%2==0)
sum+=i;
}
printf
("%d\n",sum);
return
0;
}
solution
2
#
include
int
main
()
{
int
i,sum=0;
for
(i=2;i<=100;i+=2)
sum+=i;
printf
("%d\n",sum);
return
0;
}
solution
3
#
include
int
main
()
{
int
i,sum=0;
for
(i=0;i<50;i+=2)
{
sum+=i;
sum+=100-i;
}
sum+=50;
printf
("%d\n",sum);
return
0;
}
运行结果是2550.
#include
int main(void)
{
int i,s=0;
for (i=2;i<=100;i+=2) s+=i;
printf("%d",s);
return 0;
}
main()
{
int i,s=0;
for (i=2;i<=100;i+=2) s+=i;
printf("%d",s);
}