The renowned mathematician Gauss is said to have found a formula for this exact problem when he was in elementary school. And, as @Henry mentioned in the comments, this is: 
Source: Wikipedia
Since the work is done for each record, i.e. O (1) is required for each "item". Therefore, the problem is O (n ^ 2).
Visualization (also Wikipedia ) can be seen as a semi-filled square: 
source share