Program in Javascript to find the sum of N Natural Numbers - using For Loop

Posted by Rajnilari2015 under JavaScript category on | Points: 40 | Views : 344
The below function will help us to find the sum of N Natural numbers using for loop

function SumofNNaturalNumbers() {

var N=10;
var sum = 0;
for(var i=1;i<=N;i++)
alert("Sum Of N Natural Numbers : " + sum);

We are looping through the numbers till it reaches the maximum end and summing the individual numbers. Finally, printing the same using the alert.

Comments or Responses

Login to post response