题解 | 牛牛学数列
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#include <iostream>
#include<cmath>
using namespace std;
int main() {
int n;
int s =0;
cin >> n;
int j = 1;
for(int i=1;i<=n;i++)
{
s = s +pow(-1,j-1) * j;
j = j +1;
}
cout << s << endl;
}

查看3道真题和解析