Ajout exemples cours

This commit is contained in:
Geoffrey Frogeye 2016-02-03 08:25:47 +01:00
parent 3be6dfefbe
commit b960e61f3f
8 changed files with 123 additions and 0 deletions

9
Makefile Normal file
View File

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

13
P55.c Normal file
View File

@ -0,0 +1,13 @@
/* Exemple p54 */
#include <stdio.h>
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;
}

10
P64-2.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
int main() {
char c;
do {
c = getchar();
if (c != EOF) putchar(c);
} while (c != EOF);
}

9
P64.c Normal file
View File

@ -0,0 +1,9 @@
#include <stdio.h>
int main() {
char c;
while ((c = getchar()) != EOF) {
putchar(c);
}
}

16
P67-2.c Normal file
View File

@ -0,0 +1,16 @@
/* Tableau avec initialisation */
#include <stdio.h>
#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;
}

10
P68-2.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
char tab[] = "Bananier";
int main() {
int i;
printf("Nombre de caractères du tableau = %d\n", sizeof(tab)/sizeof(char));
return 0;
}

45
P71.c Normal file
View File

@ -0,0 +1,45 @@
/* Structures et tableaux */
#include <stdio.h>
#include <string.h>
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;
}

11
TestAdressage.c Normal file
View File

@ -0,0 +1,11 @@
/* Test addressage au tableau */
#include<stdio.h>
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;
}