Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
5910 谢锦卓 13求1+2-3+4-5+……n的值 C++ Accepted 0 MS 264 KB 249 2024-12-21 09:40:13

Tests(10/10):


Code:

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