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
What is the function of volatile in c language?
What does main () mean in c?
If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above
How to declare pointer variables?
Why is %d used in c?
How are Structure passing and returning implemented by the complier?
What is the use of extern in c?
write a programming in c to find the sum of all elements in an array through function.
What is void main ()?
What is bin sh c?
How can I trap or ignore keyboard interrupts like control-c?
Explain a pre-processor and its advantages.
What is header file definition?
How can I list all of the predefined identifiers?
What does == mean in texting?