This repository has been archived on 2019-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
s4-c/TP1/E7.c

54 lines
1.1 KiB
C
Raw Permalink 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;
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;
}