#include <stdio.h>
#include <math.h>
main() {
float a, b, c, x1, x2, q, d, x1r, x2r, x1i, x2i;
printf("Input coefficients of square equation a,b,c:");
scanf("%f %f %f", &a, &b, &c);
d=b*b -4.0*a*c;
if (d > 0) {
/* results are real numbers */
q = pow (d, 1./2);
x1 = (-b + q)/(2*a);
x2 = (-b - q)/(2*a);
printf ("X1=%f X2=%f\n", x1, x2);
} else if (d == 0) {
/* there’s only one result */
x1 = -b/(2*a);
printf ("X1=X2=%f\n", x1);
} else {
/* results are conjugated complex numbers */
q = pow(-d, 1./2);
x1r = -b/(2*a) ;
x2r = x1r;
x1i = q/(2*a);
x2i = -x1i;
printf ("X1 = (%f,%f)\n", x1r, x1i);
printf ("X2 = (%f,%f)\n", x2r, x2i);
}
}
If the images are hard to read simply open them in new window. Then you will see them in actual size
if (!(x>20)) printf("x is smaller or bigger than 20");
The printed statemend isn't exactly right. It should read "x is smaller or equal to 20". Everything else, though, is crystal clear.
Corrected it! Thank you! I always appreciate when readers point to my mistakes to make this articles better!
Well, this isnt really and i dont have a horrible lot of programming experince but i think your code is sorta hard to read in certian snippets. Especially for new comers
if (d > 0) {
/* results are real numbers */
q = pow (d, 1./2);
x1 = (-b + q)/(2*a);
x2 = (-b - q)/(2*a);
printf ("X1=%f X2=%f\n", x1, x2);
} else if (d == 0) {
/* there’s only one result */
x1 = -b/(2*a);
printf ("X1=X2=%f\n", x1);
} else {
/* results are conjugated complex numbers */
q = pow(-d, 1./2);
x1r = -b/(2*a) ;
x2r = x1r;
x1i = q/(2*a);
x2i = -x1i;
printf ("X1 = (%f,%f)\n", x1r, x1i);
printf ("X2 = (%f,%f)\n", x2r, x2i);
}
}
might be better as
if (d > 0)
{
/* results are real numbers */
q = pow (d, 1./2);
x1 = (-b + q)/(2*a);
x2 = (-b - q)/(2*a);
printf ("X1=%f X2=%f\n", x1, x2);
}
else if (d == 0)
{
/* there’s only one result */
x1 = -b/(2*a);
printf ("X1=X2=%f\n", x1);
}
else
{
/* results are conjugated complex numbers */
q = pow(-d, 1./2);
x1r = -b/(2*a) ;
x2r = x1r;
x1i = q/(2*a);
x2i = -x1i;
printf ("X1 = (%f,%f)\n", x1r, x1i);
printf ("X2 = (%f,%f)\n", x2r, x2i);
}
}
i think the tabs can add some clarity really i guess this is more important when you get to some more nested type structures but still its easier to follow this way imho
oh your deal kill the whitespace that might account for some issues im seeing...
what is whitespace you reefer to? yeah i see code will be re formatted just when i figure how!
[CODE] in some forums you can use tags like these for that kind of stuff...seems like a "visialcplus blogspot whould have something like this
maybe not though
[/CODE]
hi...juz wan ask what is the mean of "amp"? what is the use of that words??please reply soon...thanks...