27.3
This commit is contained in:
parent
51a2aa9776
commit
a2fb2ab9af
43
primza.c
43
primza.c
@ -1,6 +1,45 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(){
|
||||
printf("Hallo Japaner!");
|
||||
int main()
|
||||
{
|
||||
int eingabe;
|
||||
int *zahlenBisN = (int *)malloc(100 * sizeof(int));
|
||||
|
||||
do
|
||||
{
|
||||
printf("%s", "Bis wohin sollen die Primzahlen berechnet werden (Ende=0) ? ");
|
||||
scanf("%d", &eingabe);
|
||||
|
||||
if(eingabe > 100)
|
||||
{
|
||||
free(zahlenBisN);
|
||||
zahlenBisN = (int *)realloc(zahlenBisN, eingabe * sizeof(int));
|
||||
}
|
||||
|
||||
for (int i = 0; i < eingabe; ++i)
|
||||
{
|
||||
zahlenBisN[i] = i+1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < eingabe; ++i)
|
||||
{
|
||||
for (int j = 2; j < i; j++ ) {
|
||||
if (zahlenBisN[i] % j == 0)
|
||||
{
|
||||
zahlenBisN[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < eingabe; ++i)
|
||||
{
|
||||
if(zahlenBisN[i] != 0)
|
||||
{
|
||||
printf("%10d", zahlenBisN[i]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}while(eingabe != 0);
|
||||
free(zahlenBisN);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user