Skip to main content

Posts

Showing posts from June, 2020

You are given three numbers A, B & C. Print the largest amongst these three numbers.

You are given three numbers  A ,  B  &  C . Print the largest amongst these three numbers. Input Description: Three numbers are provided to you. Output Description: Find and print the largest among the three Sample Input : 1 2 3 Sample Output : 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 a = parseInt(userInput[0]); var b = parseInt(userInput[1]); var c = parseInt(userInput[2]); var d=Math.max(a,b,c) console.log(d); });

You are given Two Numbers, A and B. If C = A + B. Find C.

You are given Two Numbers, A and B. If C = A + B. Find C. Note: Round off the output to a single decimal place. Input Description: You are provided with two numbers A and B. Output Description: Find the sum of the two numbers (A + B) Sample Input : 1 1 Sample Output : 2 const readline = require('readline'); const inp = readline.createInterface({ input: process.stdin }); const userInput = []; inp.on("line", (data) => { userInput.push(data); }); inp.on("close", () => {var a = parseInt(userInput[0]); var b = parseInt(userInput[1]); var c=a+b console.log(c.toFixed(1)); });

You are provided with a number check whether its odd or even.

You are provided with a number check whether its odd or even.  Print "Odd" or "Even" for the corresponding cases. Note: In case of a decimal, Round off to nearest integer and then find the output. Incase the input is zero, print "Zero". Input Description: A number is provided as the input. Output Description: Find out whether the number is odd or even. Print "Odd" or "Even" for the corresponding cases. Note: In case of a decimal, Round off to nearest integer and then find the output. In case the input is zero, print "Zero". Sample Input : 2 Sample Output : Even 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=Math.round(a); if(b==0) consol...

You are given a number A in Kilometers. Convert this into B: Meters and C: Centi-Metres.

You are given a number  A  in Kilometers . Convert this into  B : Meters and  C : Centi-Metres . Input Description: A number "A" representing some distance in kilometer is provided to you as the input. Output Description: Convert and print this value in meters and centimeters. Sample Input : 2 Sample Output : 2000 200000 const readline = require('readline'); const inp = readline.createInterface({ input: process.stdin }); const userInput = []; inp.on("line", (data) => { userInput.push(data); }); inp.on("close", () => {var a = parseInt(userInput[0]); var b = (a*1000); var c=(b*100); console.log(b); console.log(c); });

You are provided with a number "N", Find the Nth term of the series: 1, 4, 9, 25, 36, 49, 64, 81, .......

You are provided with a number " N ", Find the  N th  term of the series: 1, 4, 9, 25, 36, 49, 64, 81, ....... (Print " Error " if N = negative value and 0 if  N = 0). Input Description: An integer N is provided to you as the input. Output Description: Find the Nth term in the provided series. Sample Input : 18 Sample Output : 324 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]); console.log(a*a); });

You are provided with two numbers. Find and print the smaller number.

You are provided with two numbers. Find and print the smaller number. Input Description: You are provided with two numbers as input. Output Description: Print the small number out of the two numbers. Sample Input : 23 1 Sample Output : 1 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]); console.log(Math.min(a,b)); });

Using the method of looping, write a program to print the table of 9 till N in the format as follows: (N is input by the user)

Using the method of looping, write a program to print the table of 9 till N in the format as follows: (N is input by the user) 9 18 27... Print NULL if 0 is input Input Description: A positive integer is provided as an input. Output Description: Print the table of nine with single space between the elements till the number that is input. Sample Input : 3 Sample Output : 9 18 27 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 N = parseInt(data[0]); var a=[]; for(i=1;i<=N;i++) {a[i-1]=9*i;} var b=""; for(i=0;i<N;i++) {if(i==N-1) b=b+a[i] else (b=b+a[i]+" ") } console.log(b) });

You are given with Principle amount($), Interest Rate(%) and Time (years) in that order. Find Simple Interest.

You are given with  Principle amount($) , Interest Rate(%)  and  Time (years)  in that order. Find Simple Interest . Print the output up to two decimal places (Round-off if necessary). (S.I. = P*T*R/100) Input Description: Three values are given to you as the input. these values correspond to Principle amount, Interest Rate and Time in that particular order. Output Description: Find the Simple interest and print it up to two decimal places. Round off if required. Sample Input : 1000 2 5 Sample Output : 100.00 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 = parseInt(data[2]); var d =b/100; var e=a*d*c; console.log(e.toFixed(2)); });

You are given with a number A i.e. the temperature in Celcius. Write a program to convert this into Fahrenheit.

You are given with a number  A  i.e. the temperature in Celcius. Write a program to convert this into Fahrenheit.  Note: In case of decimal values, round-off to two decimal places. Input Description: A number is provided in Celcius as the input of the program. Output Description: The output shall be the temperature converted into Fahrenheit corresponding to the input value print up to two decimal places and round off if required. Sample Input : 12 Sample Output : 53.60 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=(a*1.8+32); console.log(b.toFixed(2)); });

Print the First 3 multiples of the given number "N". (N is a positive integer)

Print the First 3 multiples of the given number " N ". ( N is a positive integer) Note: print the characters with a single space between them. Input Description: A positive integer is provided to you as an input. Output Description: Print the First 3 multiples of the number with single spaces between them as an output. Sample Input : 2 Sample Output : 2 4 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]); console.log(a,a*2,a*3); });

The area of an equilateral triangle is ¼(√3a2) where "a" represents a side of the triangle. You are provided with the side "a". Find the area of the equilateral triangle.

The area of an equilateral triangle is ¼(√3a 2 ) where " a " represents a side of the triangle. You are provided with the side " a ". Find the area of the equilateral triangle. Input Description: The side of an equilateral triangle is provided as the input. Output Description: Find the area of the equilateral triangle and print the answer up to 2 decimal places after rounding off. Sample Input : 20 Sample Output : 173.21 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]); b= Math.sqrt(3); c=(1/4)*b*a*a; console.log(c.toFixed(2)); });

Let "A" be a string. Remove all the whitespaces and find it's length.

Let " A "  be a string. Remove all the whitespaces and find it's length. Input Description: A string is provide as an input Output Description: Remove all the whitespaces and then print the length of the remaining string. Sample Input : Lorem Ipsum Sample Output : 10 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 =''; for(i=0;i<data.length;i++) a=a+data[i]; console.log(a.length) });

Let "A" be a year, write a program to check whether this year is a leap year or not. Print "Y" if its a leap year and "N" if its a common year.

Let " A "  be a year, write a program to check whether this year is a leap year or not. Print " Y " if its a leap year and " N " if its a common year. Input Description: A Year is the input in the form of a positive integer. Output Description: Print "Y" if its a leap year and "N" if its a common year. Sample Input : 2020 Sample Output : Y const readline = require('readline'); const inp = readline.createInterface({ input: process.stdin }); const userInput = []; inp.on("line", (data) => { userInput.push(data); }); inp.on("close", () => {var a = parseInt(userInput[0]); if(a%4==0) console.log("Y"); else console.log("N"); });

You will be provided with a number. Print the number of days in the month corresponding to that number.

You will be provided with a number. Print the number of days in the month corresponding to that number. Note: In case the input is February, print 28 days. If the Input is not in valid range print "Error". Input Description: The input is in the form of a number. Output Description: Find the days in the month corresponding to the input number. Print Error if the input is not in a valid range. Sample Input : 8 Sample Output : 31 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==2) console.log("28") else if(a==1||a==3||a==5||a==7||a==8||a==10||a==12) console.log("31") else if (a==2||a==4||a==6||a==9||a==11) console.log("30") else if(a<1||a>12) console.lo...

You are given A = Length of a rectangle & B = breadth of a rectangle. Find its area “C”.

You are given A = Length of a rectangle & B = breadth of a rectangle. Find its area “C”. (A and B are natural numbers) Input Description: The inputs are two natural numbers representing the length and the breadth of a rectangle. Output Description: Find the area of the rectangle formed by the provided input. Round off the answer to the first decimal place if required. Sample Input : 2 3 Sample 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 a = parseInt(userInput[0]);  var b = parseInt(userInput[1]);  console.log(a*b);  });

You are provided with a number, "N". Find its factorial.

You are provided with a number, " N ". Find its factorial. Input Description: A positive integer is provided as an input. Output Description: Print the factorial of the integer. Sample Input : 2 Sample Output : 2 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 factorial=1; for(i=1;i<=a;i++) factorial=factorial*i; console.log(factorial) });

You are given with a number "N", find its cube.

You are given with a number "N", find its cube. Input Description: A positive integer is provided. Output Description: Find the cube of the number. Sample Input : 2 Sample Output : 8 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]); console.log(a*a*a); });

You are given the coefficients of a quadratic equation in order A, B & C.

You are given the coefficients of a quadratic equation in order A, B & C. Where A is the coefficient of X 2 ,  B is the coefficient of X and C is the constant term in the most simplified form. Example: For  X 2  + 5X + 6 = 0, you are given the input as: 1 5 6. Write a program to find all of the roots of the quadratic. Note: The output should be up to 2nd decimal place (round off if needed) and in case of a recurring decimal use braces i.e. for eg: 0.33333..... => 0.33. Note: Use Shri Dharacharya's Method to solve i.e. X = {-b + √(b² - 4ac) } / 2a & {-b-√(b² -4ac)} / 2a Input Description: Three numbers corresponding to the coefficients of x(squared), x and constant are given as an input in that particular order Output Description: Print the two values of X after rounding off to 2 decimal places if required. Sample Input : 1 5...

You are provided with the radius of a circle "A". Find the length of its circumference.

You are provided with the radius of a circle "A". Find the length of its circumference. Note: In case the output is coming in decimal, roundoff to 2nd decimal place. In case the input is a negative number, print "Error". Input Description: The Radius of a circle is provided as the input of the program. Output Description: Calculate and print the Circumference of the circle corresponding to the input radius up to two decimal places. Sample Input : 2 Sample Output : 12.57 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 = (2*3.142*a) if(a>=-1) console.log(b.toFixed(2)); else console.log("error") });