#K48882. Nth Triangular Number
Nth Triangular Number
Nth Triangular Number
Given a positive integer n, your task is to compute the nth triangular number. The nth triangular number is defined as the sum of the first n natural numbers. It can be calculated using the formula:
\( T_n = \frac{n(n+1)}{2} \)
For example, when n = 4, the triangular number is 10 because 1 + 2 + 3 + 4 = 10.
Ensure that your solution reads input from stdin and prints the result to stdout.
inputFormat
The input consists of a single line containing one positive integer n.
Example: 4
outputFormat
Output the nth triangular number as a single integer.
Example: For input 4
, the output should be 10
.
1
1