Write a program to print the sum of the first K natural numbers.
Write a program to print the sum of the first K natural numbers.
Input Size : n <= 100000
Sample Testcase :
INPUT
3
OUTPUT
Input Size : n <= 100000
Sample Testcase :
INPUT
3
OUTPUT
6
const readline = require('readline');
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
var data = userInput[0].split(" ");
var a = parseInt(data[0]);
var total=0;
for (i=0;i<=a;i++)
{total=total+i}
console.log(total)
});
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
var data = userInput[0].split(" ");
var a = parseInt(data[0]);
var total=0;
for (i=0;i<=a;i++)
{total=total+i}
console.log(total)
});
Comments
Post a Comment