Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
8705b7b629
46
primza.c
Normal file
46
primza.c
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user