This repository has been archived on 2019-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
s4-c/TP1/E7.c
2016-01-20 10:03:02 +01:00

55 lines
1.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Affiche une table de multiplication */
#include <stdio.h>
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;
}