Browse Source

Merge branch 'refactoring'

remotes/origin/tictactoedev
fdai7754 11 months ago
parent
commit
7a1b4c4ffb
  1. 9
      src/magiceightball.c
  2. 18
      src/minirechner.c

9
src/magiceightball.c

@ -2,9 +2,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
int run_magiceightball() {
int gib_zufallszahl_aus_16() {
srand(time(NULL)); srand(time(NULL));
return rand() % 16;
}
int run_magiceightball() {
char antwort[16][100] = { char antwort[16][100] = {
"Ja", "Ja",
@ -30,7 +33,7 @@ int run_magiceightball() {
char fragesatz[100]; char fragesatz[100];
fgets(fragesatz, sizeof(fragesatz), stdin); fgets(fragesatz, sizeof(fragesatz), stdin);
int randomIndex = rand() % 16;
int randomIndex = gib_zufallszahl_aus_16();
printf("%s\n", antwort[randomIndex]); printf("%s\n", antwort[randomIndex]);
return 0; return 0;

18
src/minirechner.c

@ -95,22 +95,22 @@ float rest(float a, float b) {
// groesster gemeinsammer Teiler // groesster gemeinsammer Teiler
float groesster_gemeinsammer_teiler(float a, float b) { float groesster_gemeinsammer_teiler(float a, float b) {
float gr, kl;
float gross, klein;
float rest = 1; float rest = 1;
if (a > b) { if (a > b) {
gr = a;
kl = b;
gross = a;
klein = b;
} }
else { else {
gr = b;
kl = a;
gross = b;
klein = a;
} }
while (rest != 0) { while (rest != 0) {
rest = fmod(gr, kl);
gr = kl;
kl = rest;
rest = fmod(gross, klein);
gross = klein;
klein = rest;
} }
return gr;
return gross;
} }
// kleinstes gemeinsammes Vielfaches // kleinstes gemeinsammes Vielfaches

Loading…
Cancel
Save