sum of all integer numbers(坑题,水题)

来源:互联网 发布:怎么删除自己淘宝店铺 编辑:程序博客网 时间:2024/05/22 13:32
描述
Your task is to find the sum of all integer numbers lying between 1 and N inclusive.
输入
There are multiple test cases.
The input consists of a single integer N that is not greater than 10000 by it's absolute value.
输出
Write a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.
样例输入
3
样例输出
6
#include<iostream>#include<string.h>#include<stdio.h>#include<ctype.h>#include<algorithm>#include<stack>#include<queue>#include<set>#include<math.h>#include<vector>#include<deque>#include<list>using namespace std;int main(){    int n;    //int sum=0;    while(scanf("%d",&n)!=EOF)    {        printf("%d\n", (abs(n - 1) + 1) * (1 + n) / 2);    }    return 0;}


0 0
原创粉丝点击