41 lines
821 B
C
41 lines
821 B
C
#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;
|
|
}
|