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
What are different types of operators?
Is there a built-in function in C that can be used for sorting data?
diff between exptected result and requirement?
Which is an example of a structural homology?
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
What is structure packing in c?
What are # preprocessor operator in c?
FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above
Why does everyone say not to use gets?
write a program to display all prime numbers
which type of aspect you want from the student.
Why is structure padding done in c?
What are logical errors and how does it differ from syntax errors?
What is printf () in c?
What does return 1 means in c?