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 is putchar() function?
Write a program to check whether a number is prime or not using c?
What is the correct declaration of main?
What are identifiers c?
What is extern variable in c with example?
If I have a char * variable pointing to the name of a function ..
What is the difference between declaring a variable by constant keyword and #define ing that variable?
What is character set?
How can I write a function that takes a format string and a variable number of arguments?
What is a pointer variable in c language?
write a c program to find the sum of five entered numbers using an array named number
What is sizeof in c?
What is a void * in c?
What is #error and use of it?
How can I call fortran?