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.