APL/APL1.1/TP11/filtre.c
2021-10-05 16:17:21 +02:00

46 lines
988 B
C

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void showtable(int tablesize, int* table) {
for (int i = 0; i < tablesize; i++) printf("+-----");
printf("+\n");
for (int i = 0; i < tablesize; i++) printf("| %3d ", table[i]);
printf("|\n");
for (int i = 0; i < tablesize; i++) printf("+-----");
printf("+\n");
}
void showtable2(int tablesize, int* table) {
for (int i = 0; i < tablesize; i++) if (table[i] >= 0) printf("+-----");
printf("+\n");
for (int i = 0; i < tablesize; i++) if (table[i] >= 0) printf("| %3d ", table[i]);
printf("|\n");
for (int i = 0; i < tablesize; i++) if (table[i] >= 0) printf("+-----");
printf("+\n");
}
int main(int argc, char * argv[]) {
int tab[10] = {};
srand(time(NULL));
int rand_v = rand();
for (int i = 0; i < 10; i++) {
srand(rand_v);
tab[i] = rand() % 101 > 50 ? (-rand() % 100) + 50: (rand() % 100) - 50;
rand_v = rand();
}
showtable(10, tab);
printf("\n\n");
showtable2(10, tab);
return EXIT_SUCCESS;
}