sharif


{ City } comilla
< Country > bangladesh
* Profession * study
User No # 125545
Total Questions Posted # 1
Total Answers Posted # 1

Total Answers Posted for My Questions # 1
Total Views for My Questions # 780

Users Marked my Answers as Correct # 0
Users Marked my Answers as Wrong # 0
Questions / { sharif }
Questions Answers Category Views Company eMail

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.

1 Engineering AllOther 780




Answers / { sharif }

Question { 780 }

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

#include
#include

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