123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <malloc.h>
- int main()
- {
- FILE* file;
- //char buffer[128];
- system("chcp 1251 < nul");
- FILE* input = fopen("input.txt", "r");
- if (input == NULL)
- {
- printf("Failed to open input file");
- return 1;
- }
- FILE* output = fopen("output.txt", "w");
- if (output == NULL)
- {
- printf("Failed to open output file");
- return 1;
- }
- float a, b, c;
- if (fscanf(input, "%f %f %f", &a, &b, &c) != 3)
- {
- fprintf(output, "A lot of many numbers");
- fclose(input);
- return 1;
- }
- if (a == 0)
- {
- fprintf(output, "Not have exc => a = 0");
- fclose(input);
- return 1;
- }
- fclose(input);
- float discriminant = b * b - 4 * a * c;
- if (discriminant > 0) //Äâà äåéñòâèòåëüíûõ êîğíÿ
- {
- float x1 = (-b + sqrt(discriminant)) / (2 * a);
- float x2 = (-b - sqrt(discriminant)) / (2 * a);
- fprintf(output, "Discriminant:\n%.1f\n", discriminant);
- fprintf(output, "Resultat:\nx1 = %.1f\nx2 = %.1f\n", x1, x2);
- }
- else if (discriminant == 0) //Îäèí äåéñòâèòåëüíûé êîğåíü
- {
- float x = -b / (2 * a);
- fprintf(output, "Discriminant:\n%.1f\n", discriminant);
- fprintf(output, "Resultat:\nx = %.1f\n", x);
- }
- else if (discriminant < 0)
- {
- fprintf(output, "Not have exc => ");
- fprintf(output, "Discriminant:\n%.1f\n", discriminant);
- }
- fclose(output);
- return 0;
- }
|