1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include <stdio.h>
#include <stdlib.h>
#define D 10 /* taille tableau */
main()
{
/*** Déclarations ***/
int tab[D]; /* tableau donné */
int i,j; /* indices courants */
int idecal; /* deplacement tableau */
int tmp; /* temporaire */
char signe;
/*** Saisie des données ***/
i=0;
while (i<D)
{
printf("Nombre [%d] : ", i);
scanf("%d", &tab[i]);
i++;
}
/*** Affichage du tableau ***/
printf("\nTableau :\n\n\t");
for (i=0; i<D; i++)
printf("%d\t", tab[i]);
printf("\n");
i=0;
/*** Décalage d'autant dans le tableau ***/
printf("\n\nRentrez un nombre : ");
scanf("%d", &idecal);
printf("\n\n");
/*** Décalage de gauche à droite ou inchangé dans le tableau ***/
printf("Deplacer le vecteur par la gauche (-), la droite (+) ou inchange (0) \?\n");
fflush(stdin);
printf("\n\nRentrez le signe : ");
scanf("%c", &signe);
/*** Inverser le tableau ***/
for (i=0, j=D-1 ; i<j ; i++,j--)
/*** Echange de tab[i] et tab[j] ***/
{
tmp = tab[i];
tab[i] = tab[j];
tab[j] = tmp;
}
/*** Edition des résultats ***/
printf("\n\nDecalage :\n\n\t");
for (i=0; i<D; i++)
printf("%d\t", tab[i]);
printf("\n\n");
i=0;
} |
Partager