牛牛学数列
牛牛学数列
https://ac.nowcoder.com/acm/problem/22156
#include<iostream> using namespace std; int main() { int n; int sum = 0; cin >> n; for (int i = 1; i <= n; i++) { if (i % 2 == 0) sum -= i; else sum += i; } cout << sum << endl; return 0; }
牛牛学数列
https://ac.nowcoder.com/acm/problem/22156
#include<iostream> using namespace std; int main() { int n; int sum = 0; cin >> n; for (int i = 1; i <= n; i++) { if (i % 2 == 0) sum -= i; else sum += i; } cout << sum << endl; return 0; }
相关推荐