write a c program to find the roots of a quadratic equation
ax2 + bx + c = 0
Answer Posted / shariful islam
#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
Explain what will the preprocessor do for a program?
How can variables be characterized?
What are the features of the c language?
What is pointer in c?
what are bit fields? What is the use of bit fields in a structure declaration?
Why is this loop always executing once?
What is difference between arrays and pointers?
Stimulate calculator using Switch-case-default statement for two numbers
Do you know the purpose of 'register' keyword?
to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?
why return type of main is not necessary in linux
What are the advantages of external class?
write a program to create a sparse matrix using dynamic memory allocation.
What is function in c with example?
What is memcpy() function?