Using ifelse in C programming write a C program to find all
Using \"if-else\" in C programming, write a C program to find all roots of following quadratic equation were \"a, b, c\" are integers. ax^2 + bx + c = 0 Example: Input a: 8 Input b: -4 Input c: -2 Output root1: 0.80 Output root2: -0.30 Enter values of a, b, c of quadratic equation (aX^2 + bX + c): 8 -4 -2 Two distinct and real roots exists: 0.81 and -0.31
Solution
A c program to find all roots of quadratic equation a*x^2+b*x+c using if-else :-
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,d,root1,root2;
printf(\" Enter value of a of quadratic equation (aX^2 + bX + c) : \ \");
scanf(\"%lf\",&a);
printf(\" Enter value of b of quadratic equation (aX^2 + bX + c) : \ \");
scanf(\"%lf\",&b);
printf(\" Enter value of c of quadratic equation (aX^2 + bX + c) : \ \");
scanf(\"%lf\",&c);
d=b*b-4*a*c;
if (d>0)
{
root1 = (-b + sqrt(d) ) / (2*a);
root2 = (-b - sqrt(d) ) / (2*a);
printf(\"\ root1: %lf \",root1);
printf(\"\ root2: %lf \",root2);
}
else
{
printf(\"\ Discriminant is negative!!! No roots exists!!!\");
}
printf(\"\ \");
return 0;
}
