DEV/BUT1/DEV1.1/Tableaux/miroir.c

83 lines
1.2 KiB
C
Raw Normal View History

2024-02-01 13:55:03 +01:00
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#define MAX 50
#define MIN -50
int generate_random(int min, int max)
{
return min + rand() / (RAND_MAX / (max - min + 1) + 1);
}
void affichage_tableau(int tableau[])
{
for (int i = 0; i < 10; i++)
{
if (i == 9)
{
printf("+-----+\n");
}
else
{
printf("+-----");
}
}
for (int i = 0; i < 10; i++)
{
if (i == 9)
{
printf("|%4d |\n", tableau[i]);
}
else
{
printf("|%4d ", tableau[i]);
}
}
for (int i = 0; i < 10; i++)
{
if (i == 9)
printf("+-----+\n");
else
{
printf("+-----");
}
}
}
int main(void)
{
int tab[10];
srand(time(NULL));
for (int i = 0; i < 10; i++)
{
tab[i] = generate_random(MIN, MAX);
}
affichage_tableau(tab);
int taille_tableau = 10;
for (int i = 0; i < taille_tableau / 2; i++)
{
int temp = tab[i];
tab[i] = tab[taille_tableau - 1 - i];
tab[taille_tableau - 1 - i] = temp;
}
affichage_tableau(tab);
return EXIT_SUCCESS;
}