write a c program to find the roots of a quadratic equation
ax2 + bx + c = 0
Answer Posted / adhulya
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
void RootsofQuadratic(int a, int b, int c)
{
if (a == 0)
{
printf("The value of a cannot be 0");
return;
}
int d = b*b - 4*a*c;
double SquarerootDescriminant = sqrt(abs(d));
if (d > 0)
{
printf("The Roots are Real in Nature n");
printf("%fn%f",(double)(-b + SquarerootDescriminant)/(2*a)
, (double)(-b - SquarerootDescriminant)/(2*a));
}
else if (d == 0)
{
printf("The roots are equal and Real in Nature n");
printf("%f",-(double)b / (2*a));
}
else // d < 0
{
printf("The Roots are Complex in Nature n");
printf("%f + i%fn%f - i%f", -(double)b / (2*a),SquarerootDescriminant
,-(double)b / (2*a), SquarerootDescriminant);
}
}
int main()
{
int a;
int b;
int c;
printf("For a quadratic equation of form ax2 + bx + c = 0 enter values of a, b, cn");
scanf("%d%d%d", &a, &b, &c);
RootsofQuadratic(a, b, c);
return 0;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Differentiate between a for loop and a while loop? What are it uses?
What does 1f stand for?
What is c token?
Can main () be called recursively?
Write a program to print fibonacci series using recursion?
What is the meaning of typedef struct in c?
How can I avoid the abort, retry, fail messages?
Explain how can I open a file so that other programs can update it at the same time?
Explain what is the benefit of using #define to declare a constant?
how can I convert a string to a number?
What is volatile variable in c with example?
Which is an example of a structural homology?
Explain main function in c?
what do you mean by inline function in C?
How do I send escape sequences to control a terminal or other device?