From b960e61f3f61a96773548dc72659b43deda7e86a Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Wed, 3 Feb 2016 08:25:47 +0100 Subject: [PATCH] Ajout exemples cours --- Makefile | 9 +++++++++ P55.c | 13 +++++++++++++ P64-2.c | 10 ++++++++++ P64.c | 9 +++++++++ P67-2.c | 16 ++++++++++++++++ P68-2.c | 10 ++++++++++ P71.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ TestAdressage.c | 11 +++++++++++ 8 files changed, 123 insertions(+) create mode 100644 Makefile create mode 100644 P55.c create mode 100644 P64-2.c create mode 100644 P64.c create mode 100644 P67-2.c create mode 100644 P68-2.c create mode 100644 P71.c create mode 100644 TestAdressage.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2b5064a --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +all: $(subst c,exe,$(shell ls *.c)) + +%.exe: %.c + gcc $< -o $@ + +.PHONY: all clean + +clean: + rm *.exe diff --git a/P55.c b/P55.c new file mode 100644 index 0000000..00a4ed6 --- /dev/null +++ b/P55.c @@ -0,0 +1,13 @@ +/* Exemple p54 */ + +#include + +int main() { + unsigned int x, y, z, w; + x = 1; + y = (x << 3); + z = 10; + w = (z >> 1); + printf("x, y, z, w = %d, %d, %d, %d\n", x, y, z, w); + return 0; +} diff --git a/P64-2.c b/P64-2.c new file mode 100644 index 0000000..72f2348 --- /dev/null +++ b/P64-2.c @@ -0,0 +1,10 @@ +#include + +int main() { + char c; + do { + c = getchar(); + if (c != EOF) putchar(c); + + } while (c != EOF); +} diff --git a/P64.c b/P64.c new file mode 100644 index 0000000..521ed67 --- /dev/null +++ b/P64.c @@ -0,0 +1,9 @@ +#include + +int main() { + char c; + while ((c = getchar()) != EOF) { + putchar(c); + } + +} diff --git a/P67-2.c b/P67-2.c new file mode 100644 index 0000000..eed6a31 --- /dev/null +++ b/P67-2.c @@ -0,0 +1,16 @@ +/* Tableau avec initialisation */ + +#include + +#define N 5 + +double T[N] = {-2, -1, 0, 1, 3}; + +int main() { + int i; + for (i = 0; i < N; i++) + printf("T[%d] = %lf\n", i, T[i]); + + return 0; +} + diff --git a/P68-2.c b/P68-2.c new file mode 100644 index 0000000..6efe2ea --- /dev/null +++ b/P68-2.c @@ -0,0 +1,10 @@ +#include + +char tab[] = "Bananier"; + +int main() { + int i; + printf("Nombre de caractères du tableau = %d\n", sizeof(tab)/sizeof(char)); + + return 0; +} diff --git a/P71.c b/P71.c new file mode 100644 index 0000000..88afa8b --- /dev/null +++ b/P71.c @@ -0,0 +1,45 @@ +/* Structures et tableaux */ + +#include +#include + +struct VIP { + char nom[26], prenom[26]; + long dateNai, tel; + float taille, poids; +} client[20]; + +void saisie(int i) { + printf("Nom : "); + scanf("%s", &client[i].nom); + printf("Prénom : "); + scanf("%s", &client[i].prenom); + printf("Date de naissance : "); + scanf("%ld", &client[i].dateNai); + printf("Taille : "); + scanf("%f", &client[i].taille); + printf("Poids : "); + scanf("%f", &client[i].poids); + printf("Téléphone : "); + scanf("%ld", &client[i].tel); + +} + +void lire(int i) { + printf("Nom, Prénom : %s, %s\n", client[i].nom, client[i].prenom); + printf("Date de naissance : %ld\n", client[i].dateNai); + printf("Taille : %f\n", client[i].taille); + printf("Poids : %ld\n", client[i].poids); + printf("Téléphone : %ld\n", client[i].tel); + +} + +int main() { + int i, nb; + printf("Nombre de clients : "); + scanf("%d", &nb); + for (i = 0; i < nb; ++i) saisie(i); + for (i = 0; i < nb; ++i) lire(i); + // system("pause"); // Ne fonctionne que sous Windows + return 0; +} diff --git a/TestAdressage.c b/TestAdressage.c new file mode 100644 index 0000000..a0186a4 --- /dev/null +++ b/TestAdressage.c @@ -0,0 +1,11 @@ +/* Test addressage au tableau */ + +#include + +int main() { + int a = 1, b, c; + b = ++a; + printf("L'adresse de a est %u\n", &a); + printf("L'adresse de b est %u\n", &b); + return 0; +}