From 6c2b2b8dcd34b6280fe95d2ac844c61b7b0ef29c Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Wed, 23 Mar 2016 10:29:25 +0100 Subject: [PATCH] TP4 E3 --- TP4/E1.c | 1 - TP4/E2.c | 1 - TP4/E3.c | 24 ++++++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 TP4/E3.c diff --git a/TP4/E1.c b/TP4/E1.c index 183d778..b1feee0 100644 --- a/TP4/E1.c +++ b/TP4/E1.c @@ -2,7 +2,6 @@ #include #include -#include int main(int argc, char *argv[]) { int T[] = {12, 23, 34, 45, 56, 67, 78, 89, 90}; diff --git a/TP4/E2.c b/TP4/E2.c index f7db4b2..98911fe 100644 --- a/TP4/E2.c +++ b/TP4/E2.c @@ -2,7 +2,6 @@ #include #include -#include int main(int argc, char *argv[]) { int X = 0, n, *P1, *P2; diff --git a/TP4/E3.c b/TP4/E3.c new file mode 100644 index 0000000..c218179 --- /dev/null +++ b/TP4/E3.c @@ -0,0 +1,24 @@ +/* Inversion de tableau */ + +#include +#include + +int main(int argc, char *argv[]) { + + int T[] = {12, 23, 34, 45, 56, 67, 78, 89, 90}; + int *P1, *P2, temp, n = sizeof(T)/sizeof(int); + + P2 = T + n - 1; + for (P1 = T; P1 < T + n/2; P1++, P2--) { + temp = *P1; + *P1 = *P2; + *P2 = temp; + } + + for (P1 = T; P1 < T + n; P1++) { + printf("%d, ", *P1); + } + printf("\n"); + + return 0; +}