123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include <math.h>
- #define FILE_IN "argument.txt"
- #define FILE_OUT "result.txt"
- #define BUFFER 512
- #define ERROR_OPEN_FILE -3
- #define ERROR_READ_DATA -4
- #define ERROR_INPUT_DATA -5
- #define ERROR_WRITE_DATA -6
- struct QuadraticEquation
- {
- //коэффициенты
- double a;
- double b;
- double c;
- /// <summary>
- /// Значение дискриминанта.
- /// </summary>
- double discriminant;
- /// <summary>
- /// Кол-во корней.
- /// </summary>
- int countRoot;
- //значения корней
- double x1;
- double x2;
- };
- typedef struct QuadraticEquation QuadraticEquation;
- void solutionQuadraticEquation(QuadraticEquation* equation)
- {
- equation->discriminant = equation->b * equation->b - 4 * equation->a * equation->c;
- if (equation->discriminant < 0)
- {
- equation->countRoot = 0;
- return;
- }
- if (equation->discriminant == 0)
- {
- equation->x1 = (-(equation->b) / (2 * equation->a));
- equation->countRoot = 1;
- return;
- }
- if (equation->discriminant > 0)
- {
- equation->x1 = (-equation->b + sqrtf(equation->discriminant)) / (2 * equation->a);
- equation->x2 = (-equation->b - sqrtf(equation->discriminant)) / (2 * equation->a);
- equation->countRoot = 2;
- return;
- }
- }
|