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.

156 lines
3.0 KiB

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 string_character_counter(char string[]) {
  48. int stringLength = 0;
  49. for (int i = 0; string[i] != '\0'; i++) {
  50. stringLength++;
  51. }
  52. return stringLength;
  53. }
  54. int characterAppearanceInString(char c, char string[]) {
  55. int appear = 0;
  56. for (int i = 0; i < string_character_counter(string); i++) {
  57. if (string[i] == c) {
  58. appear++;
  59. }
  60. }
  61. return appear;
  62. }
  63. // Function to calculate the sine of an angle in radians
  64. float sine(float x) {
  65. return sin(x);
  66. }
  67. // Function to calculate the cosine of an angle in radians
  68. float cosine(float x) {
  69. return cos(x);
  70. }
  71. // Function to calculate the tangent of an angle in radians
  72. float tangent(float x) {
  73. return tan(x);
  74. }
  75. // Function to calculate the arc sine of a value and return the result in radians
  76. float arcSine(float x) {
  77. if (x >= -1 && x <= 1) {
  78. return asin(x);
  79. }
  80. else {
  81. printf("Error: Invalid input for arc sine!\n");
  82. return 0;
  83. }
  84. }
  85. // Function to calculate the arc cosine of a value and return the result in radians
  86. float arcCosine(float x) {
  87. if (x >= -1 && x <= 1) {
  88. return acos(x);
  89. }
  90. else {
  91. printf("Error: Invalid input for arc cosine!\n");
  92. return 0;
  93. }
  94. }
  95. // Function to calculate the arc tangent of a value and return the result in radians
  96. float arcTangent(float x) {
  97. return atan(x);
  98. }
  99. // Function to convert degrees to radians
  100. float degreesToRadians(float x) {
  101. return x * (M_PI / 180);
  102. }
  103. // Function to convert radians to degrees
  104. float radiansToDegrees(float x) {
  105. return x * (180 / M_PI);
  106. }
  107. // Function to calculate the base 10 logarithm of a number and add 1
  108. float logarithmPlusOne(float x) {
  109. if (x > 0) {
  110. return log10(x) + 1;
  111. }
  112. else {
  113. printf("Error: Invalid input for logarithm + 1!\n");
  114. return 0;
  115. }
  116. }
  117. // Function to calculate the natural logarithm (base e) of a number and add 1
  118. float naturalLogarithmPlusOne(float x) {
  119. if (x > 0) {
  120. return log(x) + 1;
  121. }
  122. else {
  123. printf("Error: Invalid input for natural logarithm + 1!\n");
  124. return 0;
  125. }
  126. }