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.



Write a C program to solve the quadratic equation ax^2+bx+c=0. A quadratic equation has two roots..

Answer / sharifulislam

#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

Post New Answer

More Engineering AllOther Interview Questions

Tell me about a major problem you recently handled. Were you successful in resolving it? in petroleum side ?

0 Answers   Byco,


i want questions only on code part like general logics in c and java

0 Answers  


main() { int y=10; if(y++>9 && y++!=10 && y++>10) { printf("%d",y); else printf("%d",y); } }

4 Answers   Wipro,


for us visa interiew which file i have to carry(for example :folder file,gip file or other).please give me the answer .becoze the us consulate asks my documents, tommorow morning my interview so please grant me answer

1 Answers   US Consulate,


explain about scope and storage class in oops

0 Answers  






hi frnds,im from andhra pradesh.i gt selected in sbi exam.my interview is on 3rd may'10.i applied under bc-e category as i belong to muslim "shaik".but nw i came to knw that it does not apply to bank exams.plz help me out.i have bc-e certificate issued by my area mro in feb'10.is this sufficient r else i had to carry other certificate..

1 Answers  


why do we join in bpo?

1 Answers  


There are n points and each point enclose with x and y axis form a rectangle and find the point using a program which forms the smallest rectangle?

0 Answers  


Is there any difference between the concepts of encoding,decoding and encryption and decryption?

0 Answers  


WAP in Java to print the format AMIT M I T

0 Answers  


what is the purpose of expansion tank in closed cooling water system?

3 Answers  


Give a brief description of the following terms: a) Play head b) Symbol c) Tweening d) ActionScript e) Frame rate f) Library panel g) Masking h) Context – sensitive Property Inspector i) Bandwidth Profiler j) Frame Label

0 Answers  


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4452)
  • Electrical Engineering Interview Questions Electrical Engineering (16638)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)