This is the code that i used to achieve the task at hand.
Primzahlen
int main(){
int a, b, n, h;
int c = 2, m = 0;
int flg = 0;
int flg2 = 0;
int l = 0;
int j = 0;
int i,d,k;
int arra[100] = {};
int arrb[100] = {};
printf("Geben Sie die erste naturliche Zahl ein: ");
scanf("%d", &a);
printf("Geben Sie die zweite naturliche Zahl ein: ");
scanf("%d", &b);
printf("\n");
if(a > b){
h = a;
n = b;
}
else{
h = b;
n = a;
}
printf("Dies sind die Primzahlen: ");
while(c <= a){
m = c/2;
flg = 0;
for(i = 2; i <= m; i++){
if(c % i == 0){
flg = 1;
break;
}
}
if(flg == 0){
printf("%d, ", c);
}
c++;
}
m = h/2;
for(i = 2; i <= m; i++){
if(h % i == 0){
arrb[j] = i;
j++;
}
}
m = n/2;
for(i = 2; i <= m; i++){
if(n%i==0){
arra[l] = i;
l++;
}
}
printf("\n");
printf("\n");
printf("Dies sind die grosste gemeinsame Teiler: ");
for(k = 0; k < j; k++){
for(d = 0; d < l; d++){
if(arra[k] == arrb[d]){
printf("%d ",arra[k]);
flg2 = 1;
}
}
}
if (flg2 == 0){
printf("teilerfremd");
}
printf("\n");
return 0;
}