zhaojiedi1992

nyoj436sum of all integer numbers

sum of all integer numbers

时间限制:1000 ms  |  内存限制:65535 KB
难度:0
 
描述
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
View Code
 
#include<stdio.h>
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n>0)printf("%d\n",n*(n+1)/2);
        if(n<=0)
            {
                n=-n;printf("%d\n",-n*(n+1)/2+1);
            }
    }
    return 0;
}
        

 

来源

分类:

技术点:

相关文章:

  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-10
  • 2022-12-23
  • 2022-01-02
  • 2021-09-18
猜你喜欢
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2021-12-11
  • 2022-12-23
  • 2021-11-11
相关资源
相似解决方案