Question one hundred and six: Sum of Natural Numbers

Source: Internet
Author: User

[Plain] Description
 
 
Calculate S = 1 + (1 + 2) + (1 + 2 + 3) +... + (1 + 2 +... + N ). If N is known, write the program to find S.
 
 
Input
 
The first line has an integer T, indicating that there are T groups of test data. Line 2 ~ Row T + 1 has 1 integer N, 1 <= N <= 200.
 
Output
 
For each group of input data, the output line contains an integer, that is, the value of S.
 
Sample Input
 
 
2
1
200
 
Sample Output
 
 
1
1353400

Description


Calculate S = 1 + (1 + 2) + (1 + 2 + 3) +... + (1 + 2 +... + N ). If N is known, write the program to find S.


Input

The first line has an integer T, indicating that there are T groups of test data. Line 2 ~ Row T + 1 has 1 integer N, 1 <= N <= 200.

Output

For each group of input data, the output line contains an integer, that is, the value of S.

Sample Input


2
1
200

Sample Output


1
1353400
 


[Plain] # include <stdio. h>
 
Int SUM (int num );
 
Int main ()
{
Int I;
Int n;
Int num;
Int sum;

Scanf ("% d", & n );
 
While (n --)
{
Scanf ("% d", & num );
Sum = 0;
 
For (I = 1; I <= num; I ++)
{
Sum + = SUM (I );
}
 
Printf ("% d", sum );
 
If (n> 0)
{
Printf ("\ n ");
}
}
 
Return 0;
}
 
Int SUM (int num)
{
Int I;
Int sum = 0;
 
For (I = 1; I <= num; I ++)
{
Sum + = I;
}
 
Return sum;
}

# Include <stdio. h>

Int SUM (int num );

Int main ()
{
Int I;
Int n;
Int num;
Int sum;

Scanf ("% d", & n );

While (n --)
{
Scanf ("% d", & num );
Sum = 0;

For (I = 1; I <= num; I ++)
{
Sum + = SUM (I );
}

Printf ("% d", sum );

If (n> 0)
{
Printf ("\ n ");
}
}

Return 0;
}

Int SUM (int num)
{
Int I;
Int sum = 0;

For (I = 1; I <= num; I ++)
{
Sum + = I;
}

Return sum;
}

 
 


 

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.