Write a C program to solve the quadratic equation ax^2+bx+c=0.
A quadratic equation has two roots which are given by the following two formulas:
root1= -b+sqrt(b^2-4*a*c)/2*a
root1= -b-sqrt(b^2-4*a*c)/2*a
The program request the user for input a,b,c and the output will be root1 and root2.
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c;
float d,root1,root2;
printf("Enter quadratic equation in the format ax^2+bx+c: ");
scanf("%fx^2%fx%f",&a,&b,&c);
d = b * b - 4 * a * c;
if(d < 0){
printf("Roots are complex number.
");
return 0;
}
root1 = ( -b + sqrt(d)) / (2* a);
root2 = ( -b - sqrt(d)) / (2* a);
printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2);
return 0;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
tell about ur self
3 Answers American Megatrends, CTS,
what is compiler
I'm currently placed in Lahore Pakistan. where can i do Microsoft certification. let me know the best place to do.?
send me e-mail on dell tech question papers 2011 -2012
Some question are asked from computers also. How we calculate sum in Excel? can we find cube root in Excel if yes , how? If i want to send excel sheet to 10 different person, how i can send it ( don`t tell me by mailing) condition given by interviewer.If A=.03rs(tsqr), value of r increase by 50%, s by 30% & t decrease by 20%. find value of A. If two coins having dia 25 & 16 they are rotate in their axis , Coin having dia 25 reach a point at x per sec, in how many min coin having dia 16 reach that place, Both are rotating in same direction.
compair and contrast procedrual and object oriented programming language
java is called platform independent but JVM is required for same operating system why?
What is the pattern for HAL Online-exam?
how to hack email id & passward
T is a tree and V is a vertex of T of maximum degree in T, say the degree of V in n. Prove that T has atleast n vertices of degree 1.
what is the differance between a technology and an engineering ?
How much engineering percentage is required to get admission in MS (USA)
Civil Engineering (5086)
Mechanical Engineering (4456)
Electrical Engineering (16639)
Electronics Communications (3918)
Chemical Engineering (1095)
Aeronautical Engineering (239)
Bio Engineering (96)
Metallurgy (361)
Industrial Engineering (259)
Instrumentation (3014)
Automobile Engineering (332)
Mechatronics Engineering (97)
Marine Engineering (124)
Power Plant Engineering (172)
Textile Engineering (575)
Production Engineering (25)
Satellite Systems Engineering (106)
Engineering AllOther (1379)