View Code of Problem 30

#include<math.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {

	/*
	 计算1+2+3+...+n的和。
	输入有多组数据,每组数据包括一个正整数n。
	*/
	int n = 0 , i = 0;
	
	while( scanf("%d" , &n) != EOF ) {
		long int sum = 0;
		for( i = 1 ; i <= n ; i++)
			sum += i;
		printf("%ld\n" , sum);
	}



	return 0;
}

Double click to view unformatted code.


Back to problem 30