(datastructure1.5.1)URAL 1068 SUM(计算前n项和)

/*
 * URAL_1068.cpp
 *
 *  Created on: 2013年10月18日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>

using namespace std;

void work(int n){
	int s;
	if(n > 0){
		s = (1+n)*n/2;
	}else{
		s = (1-n)*n/2 + 1;
	}

	printf("%d\n",s);
}
int main(){
	int n;
	scanf("%d",&n);
	work(n);

	return 0;
}


你可能感兴趣的:((datastructure1.5.1)URAL 1068 SUM(计算前n项和))