I have my program below (it runs and compiles as is) , but having difficulty implement these conditions and outputs:
conditions:
1. rejecting certain coefficients if the discriminat (B^(2) -4AC) <0.
2. also having no division by zero in my program (do i use setPrecision)?
outputs:
having at least 15 spaces or so for each of the root ouput and outputting the roots in the following format:
-right justified, four decimal places accuracy, fixed point format
-right justified, two decimal places accuracy, floating point (scientific) format
- left justified, four decimal places accuracy, fixed point format
- left justified, two decimal places accuracy, floating point (scientific) format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
// Quadratic Equation.cpp : main project file.
#include<stdio.h>
#include<math.h>
int main()
{
int A, B, C;
double disc, deno, x1, x2;
printf("\n\n\t ENTER THE VALUES OF A,B,C...");
scanf("%d,%d,%d", &A, &B, &C);
disc = (B * B) - (4 * A * C);
deno = 2 * A;
if(disc > 0)
{
printf("\n\t THE ROOTS ARE REAL ROOTS");
x1 = (-B/deno) + (sqrt(disc) / deno);
x2 = (-B/deno) - (sqrt(disc) / deno);
printf("\n\n\t THE ROOTS ARE...: %f and %f\n", x1, x2);
}
else if(disc == 0)
{
printf("\n\t THE ROOTS ARE REPEATED ROOTS");
x1 = -B/deno;
printf("\n\n\t THE ROOT IS...: %f\n", x1);
}
else
printf("\n\t THE ROOTS ARE IMAGINARY ROOTS\n");
}
| |