#include <stdio.h>
#include <stdlib.h>
#define VOID 0
double x = n, y = 1.0, e = 0.000001;
while(x - y > e) {
x = (x + y) / 2;
y = n / x;
}
return x;
}
void NatureRootsQuadraticEquation(double a, double b, double c) {
double S = -b/a,
P = c/a,
discriminant = b*b - 4*a*c,
x1, x2;
x1
= (-b
+ sqrt(discriminant
)) / (2 * a
); x2
= (-b
- sqrt(discriminant
)) / (2 * a
); printf("S=%.2lf P=%.2lf\n",S
,P
); printf("Delta = %.2lf\n\tx1=%lf\n\tx2=%lf\n", discriminant
, x1
, x2
);
if(discriminant >= 0) {
if(S >= 0) {
if(P > 0) {
} else if(P < 0) {
printf("%s","x1>0; x2<0; |x1| < |x2|");
} else {
}
//it means S < 0
} else {
if(P > 0) {
} else if(P < 0) {
} else {
}
}
} else {
}
}
int main(int argc, char const *argv[]) {
//declare three variable of double
double a, b, c;
a = 1;
b = 3;
c = -2;
//if the number of the arguments is greater than one
if(argc > 1){
//convert string to double
}
//tests
if(b < 0 && c < 0) {
printf("%.3lfx^2 - %.3lfx - %.3lf = 0\n", a
, -b
, -c
); } else if(b < 0) {
printf("%.3lfx^2 - %.3lfx + %.3lf = 0\n", a
, -b
, c
); } else if(c < 0) {
printf("%.3lfx^2 + %.3lfx - %.3lf = 0\n", a
, b
, -c
); } else if(a > 0 && b > 0 && c > 0){
printf("%.3lfx^2 + %.3lfx + %.3lf = 0\n", a
, b
, c
); }
//solve
NatureRootsQuadraticEquation(a, b, c);
return VOID;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2RlZmluZSBWT0lEIDAKCmRvdWJsZSBzcXJ0KGRvdWJsZSBuKSB7CgogIGRvdWJsZSB4ID0gbiwgeSA9IDEuMCwgZSA9IDAuMDAwMDAxOwoKICB3aGlsZSh4IC0geSA+IGUpIHsKCiAgICB4ID0gKHggKyB5KSAvIDI7CgogICAgeSA9IG4gLyB4OwoKICB9CiAgcmV0dXJuIHg7Cn0KCnZvaWQgTmF0dXJlUm9vdHNRdWFkcmF0aWNFcXVhdGlvbihkb3VibGUgYSwgZG91YmxlIGIsIGRvdWJsZSBjKSB7CgogICAgZG91YmxlIFMgPSAtYi9hLAogICAgICAgICAgICBQID0gYy9hLAogICAgICAgICAgICBkaXNjcmltaW5hbnQgPSBiKmIgLSA0KmEqYywKICAgICAgICAgICAgeDEsIHgyOwogICAgeDEgPSAoLWIgKyBzcXJ0KGRpc2NyaW1pbmFudCkpIC8gKDIgKiBhKTsKICAgIHgyID0gKC1iIC0gc3FydChkaXNjcmltaW5hbnQpKSAvICgyICogYSk7CiAgICBwcmludGYoIlM9JS4ybGYgUD0lLjJsZlxuIixTLFApOwogICAgcHJpbnRmKCJEZWx0YSA9ICUuMmxmXG5cdHgxPSVsZlxuXHR4Mj0lbGZcbiIsIGRpc2NyaW1pbmFudCwgeDEsIHgyKTsKCiAgICBpZihkaXNjcmltaW5hbnQgPj0gMCkgewoKICAgICAgaWYoUyA+PSAwKSB7CgogICAgICAgICBpZihQID4gMCkgewoKICAgICAgICAgICAgcHJpbnRmKCIlcyIsIngxPjA7IHgyPjAiKTsKCiAgICAgICAgIH0gZWxzZSBpZihQIDwgMCkgewoKICAgICAgICAgICAgcHJpbnRmKCIlcyIsIngxPjA7IHgyPDA7IHx4MXwgPCB8eDJ8Iik7CgogICAgICAgICB9IGVsc2UgewoKICAgICAgICAgICAgcHJpbnRmKCIlcyIsIngxPTA7IHgyID4wIik7CiAgICAgICAgIH0KICAgICAgLy9pdCBtZWFucyBTIDwgMAogICAgICB9IGVsc2UgewoKICAgICAgICBpZihQID4gMCkgewoKICAgICAgICAgICBwcmludGYoIiVzIiwieDE8MDsgeDI8MCIpOwoKICAgICAgICB9IGVsc2UgaWYoUCA8IDApIHsKCiAgICAgICAgICAgcHJpbnRmKCIlcyIsIngxPjA7IHgyPDAiKTsKCiAgICAgICAgfSBlbHNlIHsKCiAgICAgICAgICAgcHJpbnRmKCIlcyIsIngxPTA7IHgyIDwwIik7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