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

who is your favourate actor in tollywood tellme about him in few points

0 Answers   Genpact,


What experience have you had in writing technical materials?

0 Answers   Finolex,


A person was fined for exceeding the speed limit by 10mph.another person was also fined for exceeding the same speed limit by twice the same if the second person was traveling at a speed of 35 mph. find the speed limit?

1 Answers   TCS,


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  


a particle moving in a straight line with constant acceleration has a velocity of 8m/s at one instant and 3 seconds later it has a velocity of 2m/s.find its acceleration.

1 Answers  






i need NIC written test paper or give me any idea about written exam.Plz send me at smileever8@gmail.com

0 Answers   NIC,


I am having 17 months experience in development.I want to take testing as my career.I dont have experience in testing. Will get job anywhere?

0 Answers  


minimum percentage in B.E in(INFORMATION TECHNOLOGY) to be eligible for IES exam qualification and also for reserved categories.are IT engineers are eligible for giving IES exams? please reply soon.

0 Answers  


my pc frequently rebooted on normal windows xp mode, but didnot rebooted on safemode, its works no rebooting. what problem this, pls solution.

2 Answers  


can i learn ad. java without learned core java? java is best or .net is best for summer training?

0 Answers  


Please send me the ongc old question papers

0 Answers  


pls send me rrb se(s&t)questions

0 Answers   RRB,


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