Skip to main content

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 X2,  B is the coefficient of X and C is the constant term in the most simplified form.

Example: For  X2 + 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 6
Sample Output :
-2.00
-3.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 = parseInt(data[0]);
var b= parseInt(data[1]);
var c=parseInt(data[2]);
var d=Math.sqrt((b*b)-(4*a*c))
var e=(-b+d)/(2*a)
var f=(-b-d)/(2*a)
var g=e.toFixed(2)
var h=f.toFixed(2)
console.log(g);
console.log(h)

});


Comments

Popular posts from this blog

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) });

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") });

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)); });