代码:
#includeusing namespace std;int main(){int i=1,sum=0,f=1;for (i=1;i<=99;i+=2){sum+=i;f=-f;}cout<<"sum="<<sum<<endl;return 0;}
运行结果:
代码:
#includeusing namespace std;int main(){int i=1,sum=0,f=1;for (i=1;i<=99;i+=2){sum+=i;f=-f;}cout<<"sum="<<sum<<endl;return 0;}
运行结果: