Quadratic Equation
We all know about “Quadratic Equation”. In our today’s tutorial I will try to teach you, How to create this program. Today, I will help you to make this program. First, we will try to remember this equation. See below:
First we will try to process . Think how to solve it. Very easy, isn’t it? We will declare floating number variable named ‘root, a, b, c. Than we will take user input of “a, b, c”.
Scanf(“%f %f %f”, &a, &b, &c);
After that
root = ((b*b) – 4*a*c);
to process this section. And we will also declare floating number x1, x2 variable. Equation of
x1 = - b + sqrt(root);
x2= - b - sqrt(root);
The hole code of this program is:
#include
#include
void main()
{
system("TITLE ax2+bx+c=0");
system("Color 0A");
float a, b, c, root, x1, x2, iroot;
while (1) {
system("CLS");
printf("Enter values of a b c [eg.2 3 5]: ");
scanf("%f %f %f", &a, &b, &c);
root = ((b*b)-(4*a*c)); /*Equation’s root*/
if ( root<0 i="">
printf("\n\nRoots of the equation are Imaginary\n\n");
}
else {
x1 = ((-1*(b)+sqrt(root))/(2*a));
x2 = ((-1*(b)-sqrt(root))/(2*a));
printf("\n\nX1 = %0f\nX2 = %f\n\n\n\n", x1, x2);
}
system("Pause");
}
}
Thanks to all for reading. Any problem write in comment box.
0>