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

Reverse the link list without creating new list ?

0 Answers  


sir i have 4 year gap in engineering. i would complete my degree b.tech it in 2014. it will be may be in 2nd class.my hsc is also with 2nd class. i am week in programming. Then if i want highest package upto 5-6 lacs then what should i prepare myself as a good engineer to get this package???

0 Answers  


how can read number 1 to 100,without use anyloop.

0 Answers  


What is difference between ext2 and ext3 in linux

1 Answers   NetMagic,


What is the actual procedure of charging synthetic oil if the machine is under positive refrigerant pressure.

0 Answers  






main() { int arr[]={12,14,16,18,20} printf("%u%u";arr+1,&arr+1); } //tell me the answer of this question with proper reason..:)//

1 Answers  


what is the need for oobs

0 Answers  


sir ,,kindly provide me 10 year old solved question papers of gate ,i am from CS. branch...

0 Answers  


what is D- channel ?

1 Answers   ZTE,


verbal quiz and answers

0 Answers   TCS,


hi... i just want to know that how could join the AAI with an B.E back ground??? please help me out.

0 Answers   AAI Airports Authority Of India,


How does Earthquake-proofing work?

0 Answers  


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4451)
  • Electrical Engineering Interview Questions Electrical Engineering (16632)
  • 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)