1.确认初始值sum=0和i=0
2.给i确定范围i<=100
3.用循环sum=sum+i,i=i+2直到i>100
4.输出sum
代码:
#include<stdio.h>
/*
int main()
{
int sum = 0, i = 0;
while (i <= 100) {
sum = sum + i;
i = i + 2;
}
printf("输出sum=%d",sum);
return 0;
}
*/
int main()
{
int sum = 0, i = 0;
for (i = 0 ; i <=100;i=i+2) {
sum = sum + i;
}
printf("输出sum=%d",sum);
return 0;
}