Compare commits

...

4 commits

Author SHA1 Message Date
Geoffrey Frogeye 6c2b2b8dcd TP4 E3 2016-03-23 10:29:25 +01:00
Geoffrey Frogeye b2da77824f TP4 E2
Un mix entre ce qui est demandé et ce qui me paraît plus correct.
2016-03-23 10:00:37 +01:00
Geoffrey Frogeye 72d2f70b99 TP4 E1 2016-03-23 08:35:44 +01:00
Geoffrey Frogeye 75553a72a1 Status 2016-03-23 08:19:32 +01:00
6 changed files with 122 additions and 0 deletions

27
TP4/E1.c Normal file
View file

@ -0,0 +1,27 @@
/* Pointeurs sur tableau */
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int T[] = {12, 23, 34, 45, 56, 67, 78, 89, 90};
int *P;
P=T;
// Référence
printf("T = %d ; P = %d\n", T, P); // T = 557221504 ; P = 557221504
printf("&T = %d ; &P = %d\n", &T, &P); // &T = 557221504 ; &P = 557221496
printf("*T = %d ; *P = %d\n", *T, *P); // *T = 12 ; *P = 12
// Questions
printf("%d\n", *P+2); // 14
printf("%d\n", &T[4]-3); // 557221508
printf("%d\n", P+(*P-10)); // 557221512
printf("%d\n", *(P+2)); // 34
printf("%d\n", T+3); // 557221516
printf("%d\n", *(P+*(P+8)-T[7])); // 23
printf("%d\n", &P+1); // 557221504
printf("%d\n", &T[7]-P); // 7
return 0;
}

37
TP4/E2.c Normal file
View file

@ -0,0 +1,37 @@
/* Retirer les éléments d'un tableau */
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int X = 0, n, *P1, *P2;
printf("Saississez la taille de la chaîne : ");
scanf("%d", &n);
int T[n];
for (P1 = T; P1 < T+n; P1++) {
*P1 = 0;
printf("Saississez le caractère à l'indice %d : ", P1-T);
scanf("%s", P1);
}
printf("Saississez la caractère X : ");
scanf("%s", &X);
P2 = T;
for (P1 = T; P1 < T+n; P1++) {
if (*P1 != X) {
*P2 = *P1;
P2++;
}
}
*P2 = '\0';
for (P1 = T; P1 < T+n; P1++) {
if (*P1 == '\0') {
break;
}
printf("%s", P1);
}
printf("\n");
return 0;
}

16
TP4/E2.in Normal file
View file

@ -0,0 +1,16 @@
14
L
a
n
g
a
g
e
C
e
n
P
E
I
P
e

24
TP4/E3.c Normal file
View file

@ -0,0 +1,24 @@
/* Inversion de tableau */
#include <stdlib.h>
#include <stdio.h>
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;
}

9
TP4/Makefile Normal file
View file

@ -0,0 +1,9 @@
all: $(patsubst %.c,%.exe,$(shell ls *.c))
%.exe: %.c
gcc -g $< -o $@ -lm
.PHONY: all clean
clean:
rm *.exe

9
modele.c Normal file
View file

@ -0,0 +1,9 @@
/* Exercice */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[]) {
return 0;
}