Program in Javascript to find the sum of N Natural Numbers - using mathematical formula

Rajnilari2015
Posted by Rajnilari2015 under JavaScript category on | Points: 40 | Views : 314
The below function will help us to find the sum of N Natural numbers using mathematical formula (N*(N+1))/2

function SumofNNaturalNumbers() {

var N=10;
var sum = 0;
sum = (N * (N+1)) /2;
alert("Sum Of N Natural Numbers : " + sum);
}


We know that the formula for the sum of N Natural numbers is (N*(N+1))/2 . Put the value of N at runtime to get the result.Finally, printing the same using the alert.

Comments or Responses

Login to post response