1126: 零起点学算法33——求多项式

编程入门 行业动态 更新时间:2024-10-06 10:41:16

1126: 零起点学算法33——求<a href=https://www.elefans.com/category/jswz/34/1766651.html style=多项式"/>

1126: 零起点学算法33——求多项式

Description

形如1-2+3-4...+n,你会编写吗?

 

Input

输入1个正整数n(多组数据)

n<=1000

 

Output

输出1-2+3-4...+n的值(每组数据一行)

 

Sample Input

3

 

Sample Output

2

 

Source

零起点学算法

 

Code

#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{int n;while(~scanf("%d",&n)){int ans=0;for(int i=1;i<=n;i++){if(i%2==0)ans-=i;elseans+=i;}cout<<ans<<endl;}
}

 

更多推荐

1126: 零起点学算法33——求多项式

本文发布于:2024-02-27 18:42:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1766083.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多项式   算法   起点

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!