funktioniert

This commit is contained in:
Fourian Sucipto 2025-05-15 21:22:12 +02:00
parent 8b4a7b9150
commit 437d5a9b2e

46
primza.c Normal file
View File

@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int eingabe() {
int x;
scanf("%d", &x);
return x;
}
int main() {
int input = 1;
bool *primzahlen;
while (input != 0) {
printf("Bis wohin sollen die Primzahlen berechnet werden (Ende=0) ? ");
input = eingabe();
if(input == 0){
break;
}
primzahlen = (bool *) malloc(input * sizeof(bool));
for (int i = 2; i * i <= input; i++) {
if (primzahlen[i] == true) {
for (int j = i * i; j <= input; j += i) {
primzahlen[j] = false;
}
}
}
for (int i = 2; i <= input; i++) {
if (primzahlen[i] == true) {
printf("%d ", i);
}
}
printf("\n");
free(primzahlen);
}
printf("Programm beendet");
return 0;
}