Friday, August 28, 2015

Mathematical approach to determine Sum of natural number and sum of odd natural number

sum of natural number
======================================
s  = 1 + 2     + 3     + 4     + . . . . . . + n
s  = n + (n-1) + (n-2) + (n-3) + (n-4) + ..
2s = (n+1) + (n+1) + (n+1) + (n+1) + (n+1) . . . . 
s  = ((n+1) + (n+1) + (n+1) + (n+1) + (n+1) . . . . ) / 2
s = (n(n+1)) / 2

sum of odd natural number
======================================
s = 1      + 3      + 5        + 7        +..... + (2n-1)
s = (2n-1) + (2n-3) + (2n - 5) + (2n - 7) + ....
2s = 2n + 2n + 2n + ......
2s = n * 2n 
s = n * 2n / 2
s = n * n
s = n**2

Sum of natural number in PHP

Sum of odd natural number in PHP


No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }