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 are different types of operators?

598


Is there a built-in function in C that can be used for sorting data?

744


diff between exptected result and requirement?

1594


Which is an example of a structural homology?

785


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

609






What is structure packing in c?

608


What are # preprocessor operator in c?

632


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

623


Why does everyone say not to use gets?

610


write a program to display all prime numbers

1456


which type of aspect you want from the student.

1701


Why is structure padding done in c?

645


What are logical errors and how does it differ from syntax errors?

661


What is printf () in c?

578


What does return 1 means in c?

587