From e403cd62fbafb6c4d07b971afd38989c36b32414 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Wed, 20 Jan 2016 10:03:02 +0100 Subject: [PATCH] TD1 E7 --- TP1/E7.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ TP1/Makefile | 3 +++ 2 files changed, 57 insertions(+) create mode 100644 TP1/E7.c diff --git a/TP1/E7.c b/TP1/E7.c new file mode 100644 index 0000000..2814328 --- /dev/null +++ b/TP1/E7.c @@ -0,0 +1,54 @@ +/* Affiche une table de multiplication */ +#include + +void afficherDansBase(int nombre, int base) { + int a, b, c; // Chiffres + c = nombre % base; + nombre = nombre / base; + if (nombre == 0) { + printf(" %x", c); + return; + } + b = nombre % base; + nombre = nombre / base; + if (nombre == 0) { + printf(" %x%x", b, c); + return; + } + a = nombre % base; + printf("%x%x%x", a, b, c); + return; +} + +int main() { + int b, x, y; + int const w = 3; // Taille intérieure d'une case + printf("Quelle base ?\n"); + scanf("%d", &b); + if (b < 2 || b > 16) { + printf("La base doit être comprise entre 2 et 16\n"); + return 2; + } + printf("X×Y"); + for (x = 0; x <= b; x++) { + printf("│"); + afficherDansBase(x, b); + } + for (y = 0; y <= b; y++) { + // Dessine une ligne + printf("\n───"); + for (x = 0; x <= b; x++) { + printf("┼───"); + } + printf("\n"); + + afficherDansBase(y, b); + for (x = 0; x <= b; x++) { + printf("│"); + afficherDansBase(x*y, b); + } + } + printf("\n"); + + return 0; +} diff --git a/TP1/Makefile b/TP1/Makefile index 55e816b..9ac17f5 100644 --- a/TP1/Makefile +++ b/TP1/Makefile @@ -24,6 +24,9 @@ E5-2.exe: E5-2.c E6.exe: E6.c gcc E6.c -o E6.exe +E7.exe: E7.c + gcc E7.c -o E7.exe + .PHONY: all clean clean: