Files
DEV/DEV1.1/TP15/miroir.c

50 lines
905 B
C
Raw Permalink Normal View History

2023-11-06 15:00:51 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
2024-01-08 14:05:33 +01:00
void remplissage( int tab[10]){
2023-11-06 15:00:51 +01:00
int tour,signe;
2023-11-07 17:30:28 +01:00
int tab_temp[2];
2023-11-06 15:00:51 +01:00
srand(time(NULL));
for (tour=0;tour<10;tour++){
tab[tour]=rand()%51;
2023-11-07 17:30:28 +01:00
tab_temp[0]=tab[tour];
tab_temp[1]=tab[tour]*(-1);
2023-11-06 15:00:51 +01:00
signe=rand()%2;
tab[tour]=tab_temp[signe];
}
}
2024-01-08 14:05:33 +01:00
void inversion(const int tab[10], int tab_inv[10]){
2023-11-06 15:00:51 +01:00
int tour;
for (tour=0;tour<10;tour++)
2023-11-07 17:30:28 +01:00
tab_inv[tour]=tab[(9-tour)];
2023-11-06 15:00:51 +01:00
}
void affichage( int tab[10]){
int tour;
printf("+");
for (tour=0;tour<10;tour++)
printf("-----+");
printf("\n");
printf("|");
for (tour=0;tour<10;tour++)
printf("%4d |",tab[tour]);
printf("\n");
printf("+");
for (tour=0;tour<10;tour++)
printf("-----+");
printf("\n");
2023-11-07 17:30:28 +01:00
}
2023-11-06 15:00:51 +01:00
int main(void) {
int tab[10];
int tab_inv[10];
2023-11-07 17:30:28 +01:00
remplissage(tab);
2023-11-06 15:00:51 +01:00
inversion(tab,tab_inv);
affichage(tab);
printf("\n");
printf("\n");
affichage(tab_inv);
return EXIT_SUCCESS;
}