Skip to main content

Posts

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. 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) });
Recent posts

Given 2 numbers N,M. Find their difference and check whether it is even or odd.

Given 2 numbers N,M. Find their difference and check whether it is even or odd. 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 b = parseInt(data[1]); var c=(a-b) var d=Math.abs(c) if(d%2==0)  console.log("even")  else  console.log("odd") });

You are given a task to tell whether the number is pure or not. A pure number is a number whose sum of digits is multiple of 3.

You are given a task to tell whether the number is pure or not. A pure number is a number whose sum of digits is multiple of 3. 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 = (data[0]);  var b = a.split('');  var sum=0;  for(i=0;i<b.length;i++)  {sum=sum+ +b[i]}  if(sum%3==0)  console.log("yes")  else  console.log("not")  });  

Given a number N, print yes if the number is a multiple of 7 else print no.

Given a number N, print yes if the number is a multiple of 7 else print no. 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]);  if(a%7==0)  console.log("yes")  else  console.log("no") });

You are given a number ‘n’. You have to tell whether a number is great or not. A great number is a number whose sum of digits let (m) and product of digits let(j) when summed together gives the number back m+j=n

You are given a number ‘n’. You have to tell whether a number is great or not. A great number is a number whose sum of digits let (m) and product of digits let(j) when summed together gives the number back m+j=n 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 b= String(a);  var c=[] for(i=0;i<b.length;i++)     {c[i]=b[i]}  var sum=0; for(i=0;i<c.length;i++) {sum=sum+Number(c[i])} var product=1; for(i=0;i<c.length;i++) {product=product*Number(c[i])} var d=sum+product if(d==a) console.log("Great");    else  console.log("no"); });

Given 3 numbers a,b,c print a*b mod c.

Given 3 numbers a,b,c print a*b mod c. 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 = parseFloat(data[0]);  var b= parseFloat(data[1]);  var c= parseFloat(data[2])  console.log((a*b)%c); });

concepts

Rahul is given a task to manipulate a string, He hired you as a developer your task is to delete all the repeating characters and print the result left. Input Description: You are given a string ‘s’ Output Description: Print the remaining string Sample Input : mississipie Sample Output : mpe     You are given a number with duplicate digits your task is to remove the immediate duplicate digits and print the result Input Description: You are given a long string of digits Output Description: Print the desired result print -1 if result length is 0 Sample Input : 1331 Sample Output : 11   Given a sentence and string S, find how many times S occurs in the given sentence.If S is not found in the sentence print -1 Input Size : |sentence| <= 1000000(complexity O(n)). Sample Testcase : INPUT I enjoy doing codekata codekata OUTPUT 1