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

How does #define work?

734


Write a program to swap two numbers without using third variable in c?

713


What is a macro?

763


Explain about the constants which help in debugging?

948


What are the complete rules for header file searching?

758






What is sizeof array?

697


Explain what are preprocessor directives?

715


Why does everyone say not to use gets?

705


What is use of #include in c?

699


Create a simple code fragment that will swap the values of two variables num1 and num2.

930


Explain heap and queue.

677


What is the right type to use for boolean values in c? Is there a standard type?

668


What does 4d mean in c?

1091


In a switch statement, what will happen if a break statement is omitted?

700


code for quick sort?

1711