includes.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include "Header.h"
  7. #include <ctype.h>
  8. #include <math.h>
  9. double plus(double a, double b) {
  10. return a + b;
  11. }
  12. double minus(double a, double b) {
  13. return a - b;
  14. }
  15. double umnosh(double a, double b) {
  16. return a * b;
  17. }
  18. double del(double a, double b) {
  19. return a / b;
  20. }
  21. void concat(char* first, char* second) {
  22. char third[512];
  23. snprintf(third, sizeof third, "%s%s", first, second);
  24. printf(third);
  25. }
  26. void inttostr(double num, char* str) {
  27. int i = 0;
  28. int otric = 0;
  29. if (num < 0) {
  30. otric = 1;
  31. num = -num;
  32. }
  33. long long intPart = (long long)num;
  34. double fpart = num - intPart;
  35. if (intPart == 0) {
  36. str[i++] = '0';
  37. }
  38. else {
  39. while (intPart > 0) {
  40. str[i++] = (intPart % 10)+'0';
  41. intPart /= 10;
  42. }
  43. }
  44. if (otric) {
  45. str[i++] = '-';
  46. }
  47. for (int j = 0; j < i / 2; j++) {
  48. char temp = str[j];
  49. str[j] = str[i - j - 1];
  50. str[i - j - 1] = temp;
  51. }
  52. str[i++] = '.';
  53. for (int j = 0; j < 6; j++) {
  54. fpart *= 10;
  55. int digit = (int)fpart;
  56. str[i++] = digit + '0';
  57. fpart -= digit;
  58. }
  59. str[i] = '\0';
  60. }
  61. double strtoInt(char* str) {
  62. double result = 0.0;
  63. int sign = 1;
  64. double dp = 1.0;
  65. int i = 0;
  66. while (isspace(str[i])) {
  67. i++;
  68. }
  69. if (str[i] == '-') {
  70. sign = -1;
  71. i++;
  72. }
  73. else if (str[i] == '+') {
  74. i++;
  75. }
  76. while (isdigit(str[i])) {
  77. result = result * 10.0 + (str[i] - '0');
  78. i++;
  79. }
  80. if (str[i] == '.') {
  81. i++;
  82. while (isdigit(str[i])) {
  83. dp *= 10.0;
  84. result += (str[i] - '0') / dp;
  85. i++;
  86. }
  87. }
  88. return sign * result;
  89. }