12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <math.h>
- void findingTheRoots(double, double, double, FILE*);
- int main()
- {
- FILE* file;
- system("chcp 1251>nul");
- FILE* input = fopen("InputFile.txt", "r");
- double a, b, c;
- if (input == NULL)
- {
- printf("Ôàéë íå íàéäåí!");
- }
- FILE* output = fopen("OutputFile.txt", "w");
- if (output == NULL)
- {
- printf("Ôàéë íå íàéäåí!");
- }
- if (fscanf(input, "%lf %lf %lf", &a, &b, &c) != 3)
- {
- fprintf(output, "Îøèáêà ïðè ñ÷èòûâàíèè êîðíåé!");
- fclose(input);
- return 1;
- }
- fclose(input);
- findingTheRoots(a,b,c,output);
- }
- void findingTheRoots(double a, double b, double c, FILE* file)
- {
- double D;
- double x1;
- double x2;
-
- if (a == 0)
- {
- fprintf(file,"Íå êâàäðàòíîå óðàâíåíèå");
- }
- else
- {
- D = pow(b, 2) - 4 * a * c;
- }
- if (D < 0)
- {
- printf("Óðàâíåíèå íå èìååò ðåøåíèÿ");
- fprintf(file,"Óðàâíåíèå íå èìååò ðåøåíèÿ");
- }
- else if (D == 0)
- {
- x1 = (-b) / (2 * a);
- printf("Äèñêðèììèíàíò: %.2lf\n", D);
- printf("x1 = %.2lf", x1);
- fprintf(file, "Äèñêðèììèíàíò: %.2lf\n", D);
- fprintf(file, "x1 = %.2lf", x1);
- }
- else
- {
- x1 = (-b + sqrt(D)) / (2 * a);
- x2 = (-b - sqrt(D)) / (2 * a);
- printf("Äèñêðèììèíàíò: %.2lf\n", D);
- printf("x1 = %.2lf, x2 = %.2lf\n", x1, x2);
- fprintf(file, "Äèñêðèììèíàíò: %.2lf\n", D);
- fprintf(file,"x1 = %.2lf, x2 = %.2lf\n", x1, x2);
- }
- fclose(file);
- return 0;
- }
|