Aller au contenu

Problème #14 - Statistique descriptive

Énoncé

Solution

/*

par Joseph Konka
*/

#include <stdio.h>
#include <stdlib.h>

#define N 10
#define HEIGHT 5

// Variables globales
int Nombre[N]={0,1,2,3,4,5,6,7,8,9};

void print111()
{
    printf("###");
}
void print101()
{
    printf("# #");
}
void print001()
{
    printf("  #");
}
void print100()
{
    printf("#  ");
}

// Ligne 1
void printLigne1(int digit)
{
    switch(digit)
    {
        case 0:
        print111();
        break;
        case 1:
        print001();
        break;
        case 2:
        print111();
        break;
        case 3:
        print111();
        break;
        case 4:
        print101();
        break;
        case 5:
        print111();
        break;
        case 6:
        print111();
        break;
        case 7:
        print111();
        break;
        case 8:
        print111();
        break;
        case 9:
        print111();
        break;
    }
    printf(" ");
}
// Ligne 2
void printLigne2(int digit)
{
    switch(digit)
    {
        case 0:
        print101();
        break;
        case 1:
        print001();
        break;
        case 2:
        print001();
        break;
        case 3:
        print001();
        break;
        case 4:
        print101();
        break;
        case 5:
        print100();
        break;
        case 6:
        print100();
        break;
        case 7:
        print001();
        break;
        case 8:
        print101();
        break;
        case 9:
        print101();
        break;
    }
    printf(" ");
}
// Ligne 3
void printLigne3(int digit)
{
    switch(digit)
    {
        case 0:
        print101();
        break;
        case 1:
        print001();
        break;
        case 2:
        print111();
        break;
        case 3:
        print111();
        break;
        case 4:
        print111();
        break;
        case 5:
        print111();
        break;
        case 6:
        print111();
        break;
        case 7:
        print001();
        break;
        case 8:
        print111();
        break;
        case 9:
        print111();
        break;
    }
    printf(" ");
}
// Ligne 4
void printLigne4(int digit)
{
    switch(digit)
    {
        case 0:
        print101();
        break;
        case 1:
        print001();
        break;
        case 2:
        print100();
        break;
        case 3:
        print001();
        break;
        case 4:
        print001();
        break;
        case 5:
        print001();
        break;
        case 6:
        print101();
        break;
        case 7:
        print001();
        break;
        case 8:
        print101();
        break;
        case 9:
        print001();
        break;
    }
    printf(" ");
}
// Ligne 5
void printLigne5(int digit)
{
    switch(digit)
    {
        case 0:
        print111();
        break;
        case 1:
        print001();
        break;
        case 2:
        print111();
        break;
        case 3:
        print111();
        break;
        case 4:
        print001();
        break;
        case 5:
        print111();
        break;
        case 6:
        print111();
        break;
        case 7:
        print001();
        break;
        case 8:
        print111();
        break;
        case 9:
        print111();
        break;
    }
    printf(" ");
}

void AfficherUneLigneDuChiffre(int line, int digit)
{
    switch(line)
    {
        case 1:
        printLigne1(digit);
        break;
        case 2:
        printLigne2(digit);
        break;
        case 3:
        printLigne3(digit);
        break;
        case 4:
        printLigne4(digit);
        break;
        case 5:
        printLigne5(digit);
        break;
    }
}

void AfficherUneLigneDuNombre(int line, int *nombre)
{
    int i;
    for(i=0; i<N; i++)
    {
        AfficherUneLigneDuChiffre(line, nombre[i]);
    }
    printf("\n");
}

void AfficherUnNombre(void)//(int *number)
{
    int ligne;

    for(ligne=1; ligne<HEIGHT+1; ligne++)
    {
        AfficherUneLigneDuNombre(ligne, Nombre);
    }
    printf("\n");
}

void AfficherUnChiffre(int digit)
{
    int i;
    for(i=0; i<HEIGHT; i++)
    {
        AfficherUneLigneDuChiffre(i+1, digit);
        printf("\n");
    }
}

int main()
{
    int ligne, chiffre;
    char number[N+1];

    printf("**Digits**\n");
    printf("0123456789\n");
    printf("\n");

    printf("Entrer un chiffre\n");
    printf(">>> ");
    scanf("%d", &chiffre);
    printf("\n");
    AfficherUnChiffre(chiffre);
    printf("\n");

    printf("Entrer un nombre\n");
    printf(">>> ");
    scanf("%s", &number);
    printf("\n");

    AfficherUnNombre();
    printf("\n");

    return 0;
}