Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
5908 詹梓涵 13求1+2-3+4-5+……n的值 C++ Accepted 0 MS 268 KB 249 2024-12-21 09:38:45

Tests(10/10):


Code:

#include<iostream> // cin\cout\endl using namespace std; int main(){ int n,z=0; cin>>n; for(int i=1;i<=n;i++){ if(i==1) z=z+i; else if(i%2==0) z+=i; else z-=i; } cout<<z<<endl; return 0; }