Compare commits
4 commits
178291f9f0
...
6c2b2b8dcd
Author | SHA1 | Date | |
---|---|---|---|
Geoffrey Frogeye | 6c2b2b8dcd | ||
Geoffrey Frogeye | b2da77824f | ||
Geoffrey Frogeye | 72d2f70b99 | ||
Geoffrey Frogeye | 75553a72a1 |
27
TP4/E1.c
Normal file
27
TP4/E1.c
Normal 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
37
TP4/E2.c
Normal 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;
|
||||
}
|
24
TP4/E3.c
Normal file
24
TP4/E3.c
Normal 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
9
TP4/Makefile
Normal file
|
@ -0,0 +1,9 @@
|
|||
all: $(patsubst %.c,%.exe,$(shell ls *.c))
|
||||
|
||||
%.exe: %.c
|
||||
gcc -g $< -o $@ -lm
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
clean:
|
||||
rm *.exe
|
Reference in a new issue