当前位置: 代码迷 >> 综合 >> NYOJ - 436 - sum of all integer numbers(注意a0)
  详细解决方案

NYOJ - 436 - sum of all integer numbers(注意a0)

热度:76   发布时间:2023-10-09 17:38:26.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

#include<cstdio>
using namespace std;
int main(){int a,ans;while(scanf("%d",&a)!=EOF){if(a>0)ans = (1+a)*a/2;else{ans = 0;for(int i=a ;i<=1 ;i++){ans += i;}		}printf("%d\n",ans);}return 0;
}


  相关解决方案