# Python program for sum of squares of n natural numbers

Here, we are going to write python program to find sum of squares of n natural numbers. To find sum of squares of n numbers we can use for loop or while loop to add the squares of each numbers one by one into sum.

Sum of squares of n natural numbers is the sum of squares of the positive numbers from 1 to nth number.Lets see practical solved example. We can use following formula to solve the query.

Formula:

sum of squares of n numbers:

12+22+32+42+52+….+(n-1)2+n2

Examples

sum of squares of 3 numbers:

12+22+32 = 1 + 4 +9 = 14

## Program 1 : Python program to find  sum of squares of n numbers using for loop

```# Program to find sum of sqaure of n numbers

n = int(input("Enter any number : "))
# initialising sum to zero
sum = 0
# use for loop to iterate through given number
for i in range(1, n+1):
sum = sum + (i*i)
# Printing sum of squares
print("Sum of squares is : ", sum)

```

## Output:

### Run 1 :Enter any number : 100Sum of squares is : 338350

%Run 2:
Enter any number : 10
Sum of squares is : 385

%Run 3:
Enter any number : 3
Sum of squares is : 14

## Program 2 : Python program to find  sum of squares of n numbers using while loop

```# Program to find sum of sqaure of n numbers

n = int(input("Enter nth number : "))
sum = 0
# use while loop
while n>0:
sum = sum + (n*n)
n = n-1
# Printing sum of squares
print("sum of squares is : ",sum)

```

## Output:

Run1

Enter nth number : 200
sum of squares is : 2686700

Run2
Enter nth number : 150
sum of squares is : 1136275

%Run 3
Enter nth number : 5
sum of squares is : 55

<