Thursday, 16 December 2021

To find the sum of squares of the first 100 natural numbers.

 sum of squares of 5 numbers:

12+22+32+42+52

Example 1: sum of squares of n numbers using for loop

n = int(input("Enter nth number : "))
sum = 0
for s in range(1, n+1):
sum = sum + (s*s)
print("Sum of squares is : ", sum)

Output:

Enter nth number : 3
Sum of squares is : 14

Enter nth number : 10
Sum of squares is : 385

No comments:

Post a Comment