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.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Please send me the ongc old question papers

2621


what is the need for oobs

1698


what is the differance between a technology and an engineering ?

1578


convert 140 N.m/cm^2 to N.m/mm^2

1605


CSS corp interview process and placement papers

1491






if we give you the job AS A PETROLEUM ENGINEER WHAT WILL YOU DO(that is extraordinary) for our company

2856


how configur net and vpn on cisco product

1526


376,188,88,40,16,4,-2. Find wrong term in series

3849


1.what a diffrenrs v-lan & (layer)l-3,l-2 bitween plz define defination of these? 2.how to configur ms outlook & lotus note (ibm)

1454


need tcs questn papers from 2007 to 2009 plzzzmail to 9015.rama@gmail.com its urgent

1505


what is the pri request of binary search

1264


Reverse the link list without creating new list ?

2195


as a student of b.tech 2nd yr which is the best place for me to do my summer training and plz also tell me the complete procedure for the entrance?

1468


Can anyone send me iocl written test paper fro computer engineers

1887


synchronous and asynchronous transmission

1477