Decision.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <windows.h>
  7. #define OUTPUTFILE "D:\\Bolshakov41p\\Processes\\Files\\Output.txt"
  8. int main(int argc, char* argv[])
  9. {
  10. system("chcp 1251>nul");
  11. HANDLE OutputFile = CreateFileA(OUTPUTFILE,
  12. GENERIC_WRITE,
  13. 0,
  14. NULL,
  15. CREATE_ALWAYS,
  16. FILE_ATTRIBUTE_NORMAL,
  17. NULL);
  18. double a = atof(argv[0]);
  19. double b = atof(argv[1]);
  20. double c = atof(argv[2]);
  21. DWORD numBytesRead;
  22. double D;
  23. double x1;
  24. double x2;
  25. char output[100];
  26. int countRoots;
  27. if (a == 0)
  28. {
  29. sprintf(output, "Íĺ ęâŕäđŕňíîĺ óđŕâíĺíčĺ");
  30. WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL);
  31. }
  32. else
  33. {
  34. D = pow(b, 2) - 4 * a * c;
  35. }
  36. if (D < 0)
  37. {
  38. printf("Óđŕâíĺíčĺ íĺ čěĺĺň đĺřĺíč˙");
  39. sprintf(output, "Óđŕâíĺíčĺ íĺ čěĺĺň đĺřĺíč˙");
  40. WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL);
  41. countRoots = 0;
  42. }
  43. else if (D == 0)
  44. {
  45. x1 = (-b) / (2 * a);
  46. printf("Äčńęđčěěčíŕíň: %.2lf\n", D);
  47. printf("x1 = %.2lf", x1);
  48. sprintf(output, "Äčńęđčěěčíŕíň: %.2lf\n", D);
  49. WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL);
  50. sprintf(output, "x1 = %.2lf", x1);
  51. WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL);
  52. countRoots = 1;
  53. }
  54. else
  55. {
  56. x1 = (-b + sqrt(D)) / (2 * a);
  57. x2 = (-b - sqrt(D)) / (2 * a);
  58. printf("Äčńęđčěěčíŕíň: %.2lf\n", D);
  59. printf("x1 = %.2lf, x2 = %.2lf\n", x1, x2);
  60. sprintf(output, "Äčńęđčěěčíŕíň: %.2lf\n", D);
  61. WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL);
  62. sprintf(output, "x1 = %.2lf, x2 = %.2lf\n", x1, x2);
  63. WriteFile(OutputFile, output, strlen(output), &numBytesRead, NULL);
  64. countRoots = 2;
  65. }
  66. CloseHandle(OutputFile);
  67. return countRoots;
  68. }