mirror of
https://gitlab.gwdg.de/j.hahn02/university.git
synced 2026-01-01 14:54:25 -05:00
refactor various files
This commit is contained in:
41
S1/GdCP/uebung/testcprogram.c
Normal file
41
S1/GdCP/uebung/testcprogram.c
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
#include<stdio.h>
|
||||
|
||||
#include<string.h>
|
||||
#include<stdlib.h>
|
||||
#define N 998
|
||||
|
||||
int *find_next(int *a) {
|
||||
for (int i = 0; i < N; i++) if (a[i] != 0) return a + i;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void kill_mults(int *a, int m) {
|
||||
for (int i = 0; i < N; i++) if (a[i] % m == 0) a[i] = 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Setup all numbers
|
||||
int n[N], *c;
|
||||
int p[N], r = 0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
n[i] = i + 2;
|
||||
}
|
||||
|
||||
while (1){
|
||||
int *c = find_next(n);
|
||||
if ((c = find_next()) == NULL) break;
|
||||
p[r++] = *c;
|
||||
kill_mults(n, *c);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < r; i++) {
|
||||
printf("%d ", p[i]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user