«à l'aide»

banene -  
evilfalcon Messages postés 76 Statut Membre -
Bonjour, mon but est d'écrire un programme en c composées des fcts suivantes
-fonction saisie() qui saisie un tableau à 2 dim d éntiers
-fonction produit () qui calcule le produit de 2 matrices d éntiers et met le resultat dans une troisiéme
-fonction affichage() qui affiche la matrice resultat du produit

#include <stdio.h>
#include <stdlib.h>
void saisie (int t[10][10],int a,int b){
for (i=0;i<= a-1;i++)
{
for (j=0;j<=b-1;j++){
printf("entrer un entier");
scanf("%d",&t[i][j]);
}
}
}
void produit (int t[10][10],v[10][10], prd [10][10],int a,int b,int c){
for (i=0;i<=a-1;i++){
for (j=0;j<=b-1;j++){
prod [i][j]=0;
for (k=0;k<=c-1;k++){
prod [i][j]=prod [i][j]+t[i][k]*t[k][j];
}
}
}
}
void affichage ( int prod [10][10],int a,int b){
for (i=0;i<=a-1;i++){
for (j=0;j<=b-1;j++){
print ("%d",&prod [10][10]);
}
}}

int main(){
int i,j,k,a,b,c;

return 0;
}

1 réponse

  1. evilfalcon Messages postés 76 Statut Membre
     
    #include <stdio.h>
    #include <stdlib.h>
    
    void menu();
    char choix_menu();
    void saisie_taille(int taille[2]);
    void saisie (int matrice[10][10],int taille[2]);
    void affichage_matrice(int matrice[10][10], int taille[2]);
    void affichage(int matrice1[10][10], int matrice2[10][10], int taille1[2], int taille2[2]);
    void multiplication_matricielle(int matrice1[10][10], int matrice2[10][10], int taille1[2], int taille2[2]);
    
    
    
    int main()
    {
        menu();
        return 0;
    }
    
    void saisie (int matrice[10][10],int taille[2])
    {
        int i,j;
        saisie_taille(taille);
    
        for (i=0;i<= taille[0]-1;i++)
        {
            for (j=0;j<=taille[1]-1;j++)
            {
                printf("la valeur de ligne %d, colonne %d: ", i+1,j+1);
                scanf("%d",&matrice[i][j]);
                getchar();
            }
        }
    }
    
    void menu()
    {
        int matrice1[10][10];
        int matrice2[10][10];
        int matrice3[10][10];
        int taille1[2] = {0,0};
        int taille2[2] = {0,0};
        char choix = 'a';
        do
        {
            affichage(matrice1, matrice2, taille1, taille2);
            choix = choix_menu();
            if (choix == 'a')
            {
                saisie(matrice1, taille1);
            }
    
            if (choix == 'b')
            {
                saisie(matrice2, taille2);
            }
    
            if (choix == 'c')
            {
                multiplication_matricielle(matrice1, matrice2, taille1, taille2);
            }
    
            if (choix == 'd')
            {
                multiplication_matricielle(matrice2, matrice1, taille2, taille1);
            }
    
        }while(choix != 'q');
    }
    
    void affichage(int matrice1[10][10], int matrice2[10][10], int taille1[2], int taille2[2])
    {
    
        printf("\nMENU MULTIPLICATION DE MATRICE\n");
        printf("Matrice 1:\n");
        affichage_matrice(matrice1,taille1);
        printf("Matrice 2:\n");
        affichage_matrice(matrice2,taille2);
    
        printf("a. Remplir matrice 1. \n");
        printf("b. Remplir matrice 2. \n");
        printf("c. Multiplier matrice 1 par matrice 2.\n");
        printf("d. Multiplier matrice 2 par matrice 1.\n");
        printf("q. Quitter.\n");
    
    }
    
    void affichage_matrice(int matrice[10][10], int taille[2])
    {
        int i,j;
    
        for (i=0;i<= taille[0]-1;i++)
        {
            for (j=0;j<=taille[1]-1;j++)
            {
                printf("%d ",matrice[i][j]);
            }
            printf("\n");
        }
    }
    
    char choix_menu()
    {
        char choix;
        do
        {
            printf("votre choix?\n");
            scanf("%c",&choix);
            getchar();
            if (choix == 'a' || choix =='b' || choix =='c' || choix == 'd' ||choix =='q')
            {
                return choix;
            }
        }while(1);
    
    }
    
    void saisie_taille(int taille[2])
    {
        printf("nombre de ligne: \n");
        scanf("%d", &taille[0]);
        getchar();
        printf("\nnombre de ligne: \n");
        scanf("%d", &taille[1]);
        getchar();
        printf("\n");
    }
    
    void multiplication_matricielle(int matrice1[10][10], int matrice2[10][10], int taille1[2], int taille2[2])
    {
        int i,j,k;
        int matrice[10][10];
        int taille3[2];
        taille3[0]=taille1[0];
        taille3[1]=taille2[1];
    
        if (taille1[1] != taille2[0])
        {
            printf("multiplication de matrice impossible\n");
        }
        else
        {
            for (i=0;i<= taille3[0]-1;i++)
            {
                for (j=0;j<=taille3[1]-1;j++)
                {
                    matrice[i][j] = 0;
                    for (k=0; k<= taille1[1]-1; k++)
                    {
                        matrice[i][j] = matrice[i][j] + matrice1[i][k] * matrice2[k][j];
                    }
                }
            }
            printf("Le produit matriciel donne: \n");
            affichage_matrice(matrice, taille3);
            printf("Appuyer sur entrer pour revenir au menu!\n");
            getchar();
            printf("\n");
        }
    
    
    }
    
    -2