1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <windows.h>
- int main(int argc, char* argv[]) {
- system("chcp 1251>null");
- if (argc != 4) {
- printf("Íåâåðíîå êîëè÷åñòâî àðãóìåíòîâ.\n");
- return 1;
- }
- float a = atof(argv[1]);
- float b = atof(argv[2]);
- float c = atof(argv[3]);
- FILE* output_file = fopen("output.txt", "w");
- if (output_file == NULL) {
- printf("Ôàéë äëÿ âûâîäà íå íàéäåí.\n");
- return 1;
- }
- if (a == 0) {
- fprintf(output_file, "Ýòî íå êâàäðàòíîå óðàâíåíèå\n");
- fclose(output_file);
- return 0;
- }
- //äëÿ ïðîâåðêè äàííûõ
- /*printf("Ïîëó÷åíî àðãóìåíòîâ: %d\n", argc);
- for (int i = 0; i < argc; i++) {
- printf("argv[%d] = %s\n", i, argv[i]);
- }*/
- float discriminant = b * b - 4 * a * c;
- int rootCount = 0;
- if (discriminant > 0) {
- float x1 = (-b + sqrt(discriminant)) / (2 * a);
- float x2 = (-b - sqrt(discriminant)) / (2 * a);
- fprintf(output_file, "Äèñêðèìèíàíò:\n%.1f\n", discriminant);
- fprintf(output_file, "Äâà äåéñòâèòåëüíûõ êîðíÿ:\nx1 = %.1f\nx2 = %.1f\n", x1, x2);
- rootCount = 2;
- printf("Â ôàéë output.txt çàïèñàíû äâà äåéñòâèòåëüíûõ êîðíÿ");
- }
- else if (discriminant == 0) {
- float x = -b / (2 * a);
- fprintf(output_file, "Äèñêðèìèíàíò:\n%.1f\n", discriminant);
- fprintf(output_file, "Îäèí äåéñòâèòåëüíûé êîðåíü:\nx = %.1f\n", x);
- rootCount = 1;
- printf("Â ôàéë output.txt çàïèñàí îäèí äåéñòâèòåëüíûé êîðåíü");
- }
- else {
- fprintf(output_file, "Êîðíåé íåò, ïðè÷èíà -> ");
- fprintf(output_file, "Äèñêðèìèíàíò:\n%.1f\n", discriminant);
- rootCount = 0;
- printf("Â ôàéëå output.txt íåò êîðíåé");
- }
- fclose(output_file);
- return rootCount;
- }
|