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

Explain void pointer?

576


Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

684


where are auto variables stored? What are the characteristics of an auto variable?

574


writ a program to compare using strcmp VIVA and viva with its output.

1507


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1116






Why is c used in embedded systems?

596


What is declaration and definition in c?

511


What is the difference between the local variable and global variable in c?

520


a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none

615


What is wrong with this declaration?

597


Should a function contain a return statement if it does not return a value?

576


What is the use of printf() and scanf() functions?

616


difference between Low, Middle, High Level languages in c ?

1615


Differentiate between functions getch() and getche().

608


How can I rethow can I return a sequence of random numbers which dont repeat at all?

693