| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 
 | #include <stdio.h>
 
#define TAB_LENGTH 100
#define NAME_LENGTH 30
 
int getSigne(int annee)
{
    return annee % 12;
}
 
char isCompatible(int annee1, int annee2)
{
    int compatibilites[] = {  4, //à la case 0, on met la valeur 4 pour associer singe(0) à rat(4)
                                -1, //à la case 1 pas de compatibilité pour coq(1)
                                -1,
                                -1,
                                8,
                                4,
                                2,
                                3,
                                -1,
                                1,
                                2,
                                3
                            }; 
    int signe1 = getSigne(annee1), signe2 = getSigne(annee2);
    printf("annee : %d = %d et annee : %d = %d\n",annee1,signe1,annee2,signe2);
    return ( compatibilites[signe1] == signe2 || compatibilites[signe2] == signe1);
}    
int main(void)
{
    char* signes[] = { "singe",     //0
                            "coq",       //1
                            "chien",     //2
                            "porc",      //3
                            "rat",       //4
                            "buffle",    //5
                            "tigre",     //6
                            "lièvre",    //7
                            "dragon",    //8
                            "serpent",   //9
                            "cheval",    //10
                            "chevre"     //11
    };
    char prenoms[TAB_LENGTH][NAME_LENGTH];
    int  annees[TAB_LENGTH];
    char next = 'o';
    int i = 0;
    while (next == 'o' && i < TAB_LENGTH)
    {
        int j=0;
        printf("Quel est le prenom de la personne? ");
        scanf("%s", &prenoms[i]);
        printf("\nQuel est son annee de naissance? ");
        scanf("%d", &annees[i]);
        printf("Merci. %s est de signe %s.\n", prenoms[i], signes[getSigne(annees[i])]);
 
        for (j = 0; j < i; j++)
        {
        printf("annee : %d et annee : %d\n",annees[i],annees[j]);
            if (isCompatible(annees[i], annees[j]))
            {
                printf("%s est compatible avec %s.\n", prenoms[i], prenoms[j]);
            }
        }        
 
        printf("\nVoulez vous rentrer une autre personne (o pour oui, n pour non)? ");
        scanf("%s", &next);
        i++;
    }
    return 1;
} | 
Partager