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
all c language question
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
What is the difference between ++a and a++?
Explain what is the difference between a free-standing and a hosted environment?
What are disadvantages of C language.
What is a pragma?
What is the need of structure in c?
What is atoi and atof in c?
What is a void pointer? When is a void pointer used?
Why doesnt that code work?
What is the purpose of scanf() and printf() functions?
How do I swap bytes?
Why is C language being considered a middle level language?
How to implement a packet in C
What is pass by value in c?