Computer Science, asked by harshphilp, 8 months ago

Write a program in python to find the sum of squares of the first 100 natural numbers.

Answers

Answered by saikethansaikethan
6

Explanation:

sum of n natural numbers formula=n(n+1)/2

here,n=100

so,100(100+1)/2

50×101

=5050

hope it helps you

Answered by ravanji786
8

Answer:

The idea is to run a loop from 1 to n and for each i, 1 &lt;= i &lt;= n, find i2 to sum.</p><p></p><p># Python3 Program to </p><p></p><p># find sum of square </p><p></p><p># of first n natural  </p><p></p><p># numbers </p><p></p><p>  </p><p></p><p>  </p><p></p><p># Return the sum of </p><p></p><p># square of first n </p><p></p><p># natural numbers </p><p></p><p>def squaresum(n) : </p><p></p><p>  </p><p></p><p>    # Iterate i from 1  </p><p></p><p>    # and n finding  </p><p></p><p>    # square of i and </p><p></p><p>    # add to sum. </p><p></p><p>    sm = 0</p><p></p><p>    for i in range(1, n+1) : </p><p></p><p>        sm = sm + (i * i) </p><p></p><p>      </p><p></p><p>    return sm </p><p></p><p>  </p><p></p><p># Driven Program </p><p></p><p>n = 4</p><p></p><p>print(squaresum(n)) </p><p></p><p>  </p><p></p><p></p><p>

SEE THE ATTACHMENT FOR DETAILED SOLUTION TO THE QUESTION..

Attachments:
Similar questions