JavaScript program to find the sum of first n natural numbers:

Created with Sketch.

JavaScript program to find the sum of first n natural numbers:

let n = parseInt(prompt("Enter the number of natural numbers to add:"));
let sum = 0;

for (let i = 1; i <= n; i++) {
  sum += i;
}

console.log("The sum of first " + n + " natural numbers is: " + sum);

Leave a Reply

Your email address will not be published. Required fields are marked *