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

50 lines
891 B
C

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(int argc, char * argv[]) {
int tab[10] = {};
srand(time(NULL));
int rand_v = rand();
int max = -50;
//Génération des valeurs aléatoires et détection du maximum.
for (int i = 0; i < 10; i++) {
srand(rand_v);
tab[i] = rand() % 101 > 50 ? (-rand() % 100) + 50: (rand() % 100) - 50;
rand_v = rand();
max = max < tab[i] ? tab[i] : max;
}
//Placement de la flèche à l'endroit du maximum
for (int i = 0; i <= 10; i++) {
if (tab[i] != max) {
printf(" ");
} else {
printf(" V\n");
break;
}
}
//Génération du tableau (visuellement)
for (int i = 0; i < 10; i++) {
printf("+-----");
}
printf("+\n");
for (int i = 0; i < 10; i++) {
printf("| %3d ", tab[i]);
}
printf("|\n");
for (int i = 0; i < 10; i++) {
printf("+-----");
}
printf("+\n");
return EXIT_SUCCESS;
}