View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
Given a positive integer N. The task is to find 12 + 22 + 32 + ….. + N2.
Examples:
Input : N = 4 Output : 30 12 + 22 + 32 + 42 = 1 + 4 + 9 + 16 = 30 Input : N = 5 Output : 55
Method 1: O[N] The idea is to run a loop from 1 to n and for each i, 1