Header.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include <stdio.h>
  3. #include <malloc.h>
  4. #include <math.h>
  5. #define SIZE 100
  6. #define LEN_ONE strlen(str1)
  7. #define LEN_TWO strlen(str2)
  8. #define SUMM a+b
  9. #define DIFF a-b
  10. #define POW a*b
  11. #define DEL a/b
  12. #define LANGUAGE "chcp 1251 > nul"
  13. #define LINESIGMENT(a)(a*a)
  14. double Summa(double, double);
  15. double Difference(double, double);
  16. double Pow(double, double);
  17. double Del(double, double);
  18. char* Unification(char* str1, char* str2);
  19. void Transformation();
  20. double p = 0;
  21. double s = 0;
  22. int Line(int x1, int x2, int y1, int y2, int x3, int y3) {
  23. if (x1 == x2 || y1 == y2 || x1 == x3 || x2 == x3 || y1 == y3 || y2 == y3) {
  24. printf("Êîîðäèíàòû âòîðîé òî÷êè äîëæíû áûòü áîëüøå èëè ìåíüøå ïåðâîé");
  25. return 1;
  26. }
  27. double d1;
  28. double d2;
  29. double d3;
  30. double pp;
  31. int x = (x2 - x1);
  32. int y = (y2 - y1);
  33. int z = (x3 - x2);
  34. int c = (y3 - y2);
  35. int g = (x1 - x3);
  36. int h = (y1 - y3);
  37. d1 = sqrt(LINESIGMENT(x) + LINESIGMENT(y));
  38. /*printf("%.2lf\n", d1);*/
  39. d2 = sqrt(LINESIGMENT(z) + LINESIGMENT(c));
  40. /*printf("%.2lf\n", d2);*/
  41. d3 = sqrt(LINESIGMENT(g) + LINESIGMENT(h));
  42. /*printf("%.2lf\n", d3);*/
  43. if (d1 < (d2 + d3) && d2 < (d1 + d3) && d3 < (d2 + d1)) {
  44. p = d1 + d2 + d3;
  45. pp = p / 2;
  46. s = sqrt(pp * (pp - d1) * (pp - d2) * (pp - d3));
  47. return 0;
  48. }
  49. else {
  50. return -1;
  51. }
  52. }
  53. void Triangle() {
  54. if (Line(2, 4, 1, 2, 3, 3) == -1) {
  55. printf("Òðåóãîëüíèêà íå ñóùåñòâóåò");
  56. }
  57. else {
  58. printf("%.2lf\n", p);
  59. printf("%.2lf\n", s);
  60. }
  61. }
  62. char* Unification(char* str1, char* str2) {
  63. char* result = malloc(LEN_ONE + LEN_TWO + 1);
  64. sprintf(result, "%s %s", str1, str2);
  65. return result;
  66. }
  67. double Summa(double a, double b) {
  68. return SUMM;
  69. }
  70. double Difference(double a, double b) {
  71. return DIFF;
  72. }
  73. double Pow(double a, double b) {
  74. return POW;
  75. }
  76. double Del(double a, double b) {
  77. return DEL;
  78. }
  79. void Transformation() {
  80. printf("Âûáåðèòå æåëàåìîå äåéñòâèå:\n1 - Êîíâåðòèðîâàòü ñòðîêó â ÷èñëî\n2 - Êîíâåðòèðîâàòü ÷èñëî â ñòðîêó\n");
  81. int number;
  82. scanf("%d", &number);
  83. if (number == 1) {
  84. printf("Ââåäèòå ñòðîêó: ");
  85. char* str = malloc(sizeof(char));
  86. scanf("%s", str);
  87. double arr;
  88. sscanf(str, "%lf", &arr);
  89. printf("×èñëî: %.2lf", arr);
  90. return 0;
  91. }
  92. else if (number == 2) {
  93. printf("Ââåäèòå ÷èñëî: ");
  94. double array;
  95. scanf("%lf", &array);
  96. char* str = malloc(sizeof(char));
  97. sprintf(str, "%.2lf", array);
  98. printf("%s", str);
  99. return 0;
  100. }
  101. else {
  102. printf("Òàêîé çàäà÷è íå ñóùåñòâóåò!");
  103. return 1;
  104. }
  105. printf("\n");
  106. }