#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #define OUTPUTFILE "D:\\Bolshakov41p\\Processes\\Files\\Output.txt" int main(int argc, char* argv[]) { system("chcp 1251>nul"); HANDLE OutputFile = CreateFileA(OUTPUTFILE, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); double a = atof(argv[0]); double b = atof(argv[1]); double c = atof(argv[2]); DWORD numBytesRead; double D; double x1; double x2; char output[100]; int countRoots; if (a == 0) { sprintf(output, "Не квадратное уравнение"); WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL); } else { D = pow(b, 2) - 4 * a * c; } if (D < 0) { printf("Уравнение не имеет решения"); sprintf(output, "Уравнение не имеет решения"); WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL); countRoots = 0; } else if (D == 0) { x1 = (-b) / (2 * a); printf("Дискримминант: %.2lf\n", D); printf("x1 = %.2lf", x1); sprintf(output, "Дискримминант: %.2lf\n", D); WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL); sprintf(output, "x1 = %.2lf", x1); WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL); countRoots = 1; } 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); sprintf(output, "Дискримминант: %.2lf\n", D); WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL); sprintf(output, "x1 = %.2lf, x2 = %.2lf\n", x1, x2); WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL); countRoots = 2; } CloseHandle(OutputFile); return countRoots; }