HDUacm 1001 Sum Problem

Source: Internet
Author: User

Problem Description
Hey, welcome to HDOJ (Hangzhou Dianzi University Online Judge ).
In this problem, your task is to calculate SUM (n) = 1 + 2 + 3 +... + n.
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM (n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1 100
Sample Output
1 5050
 
Codes:
1 # include <stdio. h>
2 main ()
3 {
4 int a, I, sum;
5
6 while (scanf ("% d", & )! = EOF)
7 {
8 sum = 0;
9 for (I = 1; I <= a; I ++)
10 sum = sum + I;
11 printf ("% d \ n", sum );
12}
13}
Copy code

By Ren qilei
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.