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.

339 lines
6.9 KiB

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