题解 | 牛牛学数列

牛牛学数列

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;
}

全部评论

相关推荐

不知道怎么取名字_:现在找工作是真的太不容易了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
03-20 12:46
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务