Decision.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. void findingTheRoots(double, double, double, FILE*);
  7. int main()
  8. {
  9. FILE* file;
  10. system("chcp 1251>nul");
  11. FILE* input = fopen("InputFile.txt", "r");
  12. double a, b, c;
  13. if (input == NULL)
  14. {
  15. printf("Ôàéë íå íàéäåí!");
  16. }
  17. FILE* output = fopen("OutputFile.txt", "w");
  18. if (output == NULL)
  19. {
  20. printf("Ôàéë íå íàéäåí!");
  21. }
  22. if (fscanf(input, "%lf %lf %lf", &a, &b, &c) != 3)
  23. {
  24. fprintf(output, "Îøèáêà ïğè ñ÷èòûâàíèè êîğíåé!");
  25. fclose(input);
  26. return 1;
  27. }
  28. fclose(input);
  29. findingTheRoots(a,b,c,output);
  30. }
  31. void findingTheRoots(double a, double b, double c, FILE* file)
  32. {
  33. double D;
  34. double x1;
  35. double x2;
  36. if (a == 0)
  37. {
  38. fprintf(file,"Íå êâàäğàòíîå óğàâíåíèå");
  39. }
  40. else
  41. {
  42. D = pow(b, 2) - 4 * a * c;
  43. }
  44. if (D < 0)
  45. {
  46. printf("Óğàâíåíèå íå èìååò ğåøåíèÿ");
  47. fprintf(file,"Óğàâíåíèå íå èìååò ğåøåíèÿ");
  48. }
  49. else if (D == 0)
  50. {
  51. x1 = (-b) / (2 * a);
  52. printf("Äèñêğèììèíàíò: %.2lf\n", D);
  53. printf("x1 = %.2lf", x1);
  54. fprintf(file, "Äèñêğèììèíàíò: %.2lf\n", D);
  55. fprintf(file, "x1 = %.2lf", x1);
  56. }
  57. else
  58. {
  59. x1 = (-b + sqrt(D)) / (2 * a);
  60. x2 = (-b - sqrt(D)) / (2 * a);
  61. printf("Äèñêğèììèíàíò: %.2lf\n", D);
  62. printf("x1 = %.2lf, x2 = %.2lf\n", x1, x2);
  63. fprintf(file, "Äèñêğèììèíàíò: %.2lf\n", D);
  64. fprintf(file,"x1 = %.2lf, x2 = %.2lf\n", x1, x2);
  65. }
  66. fclose(file);
  67. return 0;
  68. }