Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
3eadbb2b2b
40
22.5.c
Normal file
40
22.5.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int ggt(int n, int m) {
|
||||
if (m == 0) {
|
||||
return n;
|
||||
} else {
|
||||
return ggt(m, n % m);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int zahl, ggt_result;
|
||||
int first_input = 1;
|
||||
|
||||
printf("Gib nicht-negative ganze Zahlen ein (Ende=0)\n");
|
||||
|
||||
while (1) {
|
||||
printf("Zahl: ");
|
||||
if (scanf("%d", &zahl) != 1 || zahl < 0) {
|
||||
printf("Ungueltige Eingabe, bitte eine nicht-negative ganze Zahl eingeben.\n");
|
||||
while (getchar() != '\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (zahl == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (first_input) {
|
||||
ggt_result = zahl;
|
||||
first_input = 0;
|
||||
} else {
|
||||
ggt_result = ggt(ggt_result, zahl);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Groesster Gemeinsamer Teiler = %d\n", ggt_result);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user