FileName.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <malloc.h>
  6. int main()
  7. {
  8. FILE* file;
  9. //char buffer[128];
  10. system("chcp 1251 < nul");
  11. FILE* input = fopen("input.txt", "r");
  12. if (input == NULL)
  13. {
  14. printf("Failed to open input file");
  15. return 1;
  16. }
  17. FILE* output = fopen("output.txt", "w");
  18. if (output == NULL)
  19. {
  20. printf("Failed to open output file");
  21. return 1;
  22. }
  23. float a, b, c;
  24. if (fscanf(input, "%f %f %f", &a, &b, &c) != 3)
  25. {
  26. fprintf(output, "A lot of many numbers");
  27. fclose(input);
  28. return 1;
  29. }
  30. if (a == 0)
  31. {
  32. fprintf(output, "Not have exc => a = 0");
  33. fclose(input);
  34. return 1;
  35. }
  36. fclose(input);
  37. float discriminant = b * b - 4 * a * c;
  38. if (discriminant > 0) //Äâà äåéñòâèòåëüíûõ êîğíÿ
  39. {
  40. float x1 = (-b + sqrt(discriminant)) / (2 * a);
  41. float x2 = (-b - sqrt(discriminant)) / (2 * a);
  42. fprintf(output, "Discriminant:\n%.1f\n", discriminant);
  43. fprintf(output, "Resultat:\nx1 = %.1f\nx2 = %.1f\n", x1, x2);
  44. }
  45. else if (discriminant == 0) //Îäèí äåéñòâèòåëüíûé êîğåíü
  46. {
  47. float x = -b / (2 * a);
  48. fprintf(output, "Discriminant:\n%.1f\n", discriminant);
  49. fprintf(output, "Resultat:\nx = %.1f\n", x);
  50. }
  51. else if (discriminant < 0)
  52. {
  53. fprintf(output, "Not have exc => ");
  54. fprintf(output, "Discriminant:\n%.1f\n", discriminant);
  55. }
  56. fclose(output);
  57. return 0;
  58. }