H. Simple Equation
Problem linkhttps://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/H
Score: 1
CPU: 1s
Memory: 512MB
CPU: 1s
Memory: 512MB
A
Quadratic
equation has two roots. Suppose those two roots are x1
and x2
. We can calculate roots using the following formula.
Now you will be given
a, b
and c
. You have to calculate two roots of Quadratic Equation.Input
Three integers
a
, b
and c
will b given in one line separated with single space.Output
Print
x1
in first line and x2
in second line. Print two digits after decimal point.Sample
Input | Output |
---|---|
2 4 -16 | 2.00 -4.00 |
Solution
#include<stdio.h> #include<math.h> int main() { int a,b,c; double x1,x2; scanf("%d%d%d",&a,&b,&c); x1=(-b+sqrt((b*b)-4*a*c))/(2*a); x2=(-b-sqrt((b*b)-4*a*c))/(2*a); printf("%.2lf\n%.2lf\n",x1,x2); return 0; }
No comments:
Post a Comment