The Quadratic Equation
Math never lies! This program is based off Euclid's algorithm...kind of. It's more like the formula we use today. Here's the code. Just copy and paste. Enjoy :)
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#include "math.h"
main()
{
float a, b, c, d, ans1, ans2;
printf("Enter the a value: ");
a = GetReal();
printf("Enter the b value: ");
b = GetReal();
printf("Enter the c value: ");
c = GetReal();
printf("This is your equation: %1.00fx^2 + %1.00fx + %1.00f\n",a,b,c);
d = b*b - 4*a*c;
printf("The discriminant of the equation is: %1.00f\n",d);
if (d==0)
{
ans1 = (-b)/(2*a);
printf("Your equation has one solution: %f\n",ans1);
}
if (d<0)
{
printf("Your equation has no solution...:(");
}
if (d>0)
{
ans1 = (-b + sqrt(d))/(2*a);
ans2 = (-b - sqrt(d))/(2*a);
printf("Your equation has two solutions: %f and %f",ans1, ans2);
}
getchar();
}
Don't worry about the libraries. They should have come with your C++ Software. I'm not so sure since I got mine from a Stanford computer class.
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#include "math.h"
main()
{
float a, b, c, d, ans1, ans2;
printf("Enter the a value: ");
a = GetReal();
printf("Enter the b value: ");
b = GetReal();
printf("Enter the c value: ");
c = GetReal();
printf("This is your equation: %1.00fx^2 + %1.00fx + %1.00f\n",a,b,c);
d = b*b - 4*a*c;
printf("The discriminant of the equation is: %1.00f\n",d);
if (d==0)
{
ans1 = (-b)/(2*a);
printf("Your equation has one solution: %f\n",ans1);
}
if (d<0)
{
printf("Your equation has no solution...:(");
}
if (d>0)
{
ans1 = (-b + sqrt(d))/(2*a);
ans2 = (-b - sqrt(d))/(2*a);
printf("Your equation has two solutions: %f and %f",ans1, ans2);
}
getchar();
}
Don't worry about the libraries. They should have come with your C++ Software. I'm not so sure since I got mine from a Stanford computer class.