You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

329 lines
6.6 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <math.h>
  5. #include "funktionen.h"
  6. void welcome() {
  7. char x[15];
  8. printf("Hallo! Wie heisst du?\n");
  9. scanf("%s", &x);
  10. printf("\nSch�ner Name, %s!\n\n", x);
  11. }
  12. int choose_program() {
  13. int i;
  14. printf("Welches der folgenden Programme moechtest du starten?\n1. Rechner.exe\n2. Gleichungen.exe\n3. TicTacToe.exe\n\n");
  15. scanf("%d", &i);
  16. return i;
  17. }
  18. int addThreeNumbers(int a, int b, int c) {
  19. return a + b + c;
  20. }
  21. int multiply(int h, int g) {
  22. return h * g;
  23. }
  24. int subtract(int num1, int num2) {
  25. return num1 - num2;
  26. }
  27. int divide(int num1, int num2) {
  28. return num1 / num2;
  29. }
  30. int power(int base, int power) {
  31. int speicher = 1;
  32. for (int i = 0; i < power; i++) {
  33. speicher *= base;
  34. }
  35. return speicher;
  36. }
  37. int x_wins_00_10_20(char board[][3]) {
  38. if (board[0][0] == 'X' && board[1][0] == 'X' && board[2][0] == 'X') {
  39. return 1;
  40. }
  41. }
  42. int x_wins_01_11_21(char board[][3]) {
  43. if (board[0][1] == 'X' && board[1][1] == 'X' && board[2][1] == 'X') {
  44. return 1;
  45. }
  46. }
  47. int x_wins_02_12_22(char board[][3]) {
  48. if (board[0][2] == 'X' && board[1][2] == 'X' && board[2][2] == 'X') {
  49. return 1;
  50. }
  51. }
  52. int x_wins_00_01_02(char board[][3]) {
  53. if (board[0][0] == 'X' && board[0][1] == 'X' && board[0][2] == 'X') {
  54. return 1;
  55. }
  56. }
  57. int o_wins_00_10_20(char board[][3]) {
  58. if (board[0][0] == 'O' && board[1][0] == 'O' && board[2][0] == 'O') {
  59. return 1;
  60. }
  61. }
  62. int o_wins_01_11_21(char board[][3]) {
  63. if (board[0][1] == 'O' && board[1][1] == 'O' && board[2][1] == 'O') {
  64. return 1;
  65. }
  66. }
  67. int o_wins_02_12_22(char board[][3]) {
  68. if (board[0][2] == 'O' && board[1][2] == 'O' && board[2][2] == 'O') {
  69. return 1;
  70. }
  71. }
  72. int o_wins_00_01_02(char board[][3]) {
  73. if (board[0][0] == 'O' && board[0][1] == 'O' && board[0][2] == 'O') {
  74. return 1;
  75. }
  76. }
  77. int string_character_counter(char string[]) {
  78. int stringLength = 0;
  79. for (int i = 0; string[i] != '\0'; i++) {
  80. stringLength++;
  81. }
  82. return stringLength;
  83. }
  84. int characterAppearanceInString(char c, char string[]) {
  85. int appear = 0;
  86. for (int i = 0; i < string_character_counter(string); i++) {
  87. if (string[i] == c) {
  88. appear++;
  89. }
  90. }
  91. return appear;
  92. }
  93. int i(int v, int r) {
  94. return v / r;
  95. }
  96. int p(int f, int a) {
  97. return f / a;
  98. }
  99. // Function to calculate the sine of an angle in radians
  100. float sine(float x) {
  101. return sin(x);
  102. }
  103. // Function to calculate the cosine of an angle in radians
  104. float cosine(float x) {
  105. return cos(x);
  106. }
  107. // Function to calculate the tangent of an angle in radians
  108. float tangent(float x) {
  109. return tan(x);
  110. }
  111. // Function to calculate the arc sine of a value and return the result in radians
  112. float arcSine(float x) {
  113. if (x >= -1 && x <= 1) {
  114. return asin(x);
  115. }
  116. else {
  117. printf("Error: Invalid input for arc sine!\n");
  118. return 0;
  119. }
  120. }
  121. // Function to calculate the arc cosine of a value and return the result in radians
  122. float arcCosine(float x) {
  123. if (x >= -1 && x <= 1) {
  124. return acos(x);
  125. }
  126. else {
  127. printf("Error: Invalid input for arc cosine!\n");
  128. return 0;
  129. }
  130. }
  131. // Function to calculate the arc tangent of a value and return the result in radians
  132. float arcTangent(float x) {
  133. return atan(x);
  134. }
  135. // Function to convert degrees to radians
  136. float degreesToRadians(float x) {
  137. return x * (M_PI / 180);
  138. }
  139. // Function to convert radians to degrees
  140. float radiansToDegrees(float x) {
  141. return x * (180 / M_PI);
  142. }
  143. // Function to calculate the base 10 logarithm of a number and add 1
  144. float logarithmPlusOne(float x) {
  145. if (x > 0) {
  146. return log10(x) + 1;
  147. }
  148. else {
  149. printf("Error: Invalid input for logarithm + 1!\n");
  150. return 0;
  151. }
  152. }
  153. // Function to calculate the natural logarithm (base e) of a number and add 1
  154. float naturalLogarithmPlusOne(float x) {
  155. if (x > 0) {
  156. return log(x) + 1;
  157. }
  158. else {
  159. printf("Error: Invalid input for natural logarithm + 1!\n");
  160. return 0;
  161. }
  162. }
  163. // Function to calculate the square root of a number and add 1
  164. float squareRootPlusOne(float x) {
  165. if (x >= 0) {
  166. return sqrt(x) + 1;
  167. }
  168. else {
  169. printf("Error: Invalid input for square root + 1!\n");
  170. return 0;
  171. }
  172. }
  173. // Function to calculate the cube root of a number and add 1
  174. float cubeRootPlusOne(float x) {
  175. return cbrt(x) + 1;
  176. }
  177. // Function to calculate the sine of an angle in degrees
  178. float sineDegrees(float x) {
  179. return sin(degreesToRadians(x));
  180. }
  181. // Function to calculate the cosine of an angle in degrees
  182. float cosineDegrees(float x) {
  183. return cos(degreesToRadians(x));
  184. }
  185. // Function to calculate the tangent of an angle in degrees
  186. float tangentDegrees(float x) {
  187. return tan(degreesToRadians(x));
  188. }
  189. // Function to calculate the square of a number
  190. float square(float x) {
  191. return x * x;
  192. }
  193. float squareRoot(float x) {
  194. if (x >= 0) {
  195. return sqrt(x);
  196. } else {
  197. printf("Error: Invalid input for square root!\n");
  198. return 0;
  199. }
  200. }
  201. // Function to calculate the cube of a number
  202. float cube(float x) {
  203. return x * x * x;
  204. }
  205. // Function to calculate the cube root of a number
  206. float cubeRoot(float x) {
  207. return cbrt(x);
  208. }
  209. // Function to calculate the absolute value of a number
  210. float absolute(float x) {
  211. return fabs(x);
  212. }
  213. // Function to calculate the logarithm (base 10) of a number
  214. float logarithm(float x) {
  215. if (x > 0) {
  216. return log10(x);
  217. } else {
  218. printf("Error: Invalid input for logarithm!\n");
  219. return 0;
  220. }
  221. }
  222. // Function to calculate the natural logarithm (base e) of a number
  223. float naturalLogarithm(float x) {
  224. if (x > 0) {
  225. return log(x);
  226. } else {
  227. printf("Error: Invalid input for natural logarithm!\n");
  228. return 0;
  229. }
  230. }
  231. // Function to calculate the factorial of a number
  232. int factorial(int x) {
  233. if (x >= 0) {
  234. int result = 1;
  235. for (int i = 1; i <= x; i++) {
  236. result *= i;
  237. }
  238. return result;
  239. } else {
  240. printf("Error: Invalid input for factorial!\n");
  241. return 0;
  242. }
  243. }
  244. // Function to calculate the floor value of a number
  245. float floorValue(float x) {
  246. return floor(x);
  247. }
  248. // Function to calculate the ceiling value of a number
  249. float ceilingValue(float x) {
  250. return ceil(x);
  251. }
  252. // Function to calculate the absolute difference between two numbers
  253. float absoluteDifference(float x, float y) {
  254. return fabs(x - y);
  255. }
  256. // Function to calculate the maximum of two numbers
  257. float maximum(float x, float y) {
  258. return fmax(x, y);
  259. }
  260. // Function to calculate the minimum of two numbers
  261. float minimum(float x, float y) {
  262. return fmin(x, y);
  263. }
  264. // Function to calculate the average of two numbers
  265. float average(float x, float y) {
  266. return (x + y) / 2;
  267. }
  268. // Function to calculate the remainder of division between two numbers
  269. float remainderValue(float x, float y) {
  270. return fmod(x, y);
  271. }