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


Please Help Members By Posting Answers For Below Questions

What is wrong with this declaration?

615


Give the rules for variable declaration?

681


provide an example of the Group by clause, when would you use this clause

1711


How many levels deep can include files be nested?

654


Explain what is wrong with this statement? Myname = ?robin?;

1039






Is c is a low level language?

568


How can I make it pause before closing the program output window?

583


hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell

1675


How can you call a function, given its name as a string?

716


Differentiate between new and malloc(), delete and free() ?

677


What is the use of function overloading in C?

683


shorting algorithmS

1805


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2124


What language is lisp written in?

621


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

657