Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void afficher_matrice(int matrice[][], int dimention)
- {
- for(int i = 0; i < dimention; i++)
- {
- for(int j = 0; j < dimention; j++)
- {
- printf("%03d\t", matrice[i][j]);
- }
- printf("\n");
- }
- }
- /*-------------------------------------------------------*/
- void remplir_matrice(int matrice[][], int dimention)
- {
- printf("veillez remplir votre matrice : \n");
- for(int i = 0; i < dimention; i++)
- {
- printf("\nLigne %d : \n", i+1);
- for(int j = 0; j < dimention; j++)
- {
- printf("Colonne %d : ", j+1);
- scanf("%d", &matrice[i][j]);
- }
- }
- }
- /*-------------------------------------------------------*/
- int calcul_element(int matrice_a[][], int matrice_b[][], int dimention, int ligne, int colonne)
- {
- int somme = 0;
- for(int i = 0; i < dimention; i++)
- {
- somme += matrice_a[ligne][i] * matrice_b[i][colonne];
- }
- return somme;
- }
- /*-------------------------------------------------------*/
- void prod(int **matrice_a, int matrice_b[][], int resultat[][], int dimention)
- {
- for(int i = 0; i < dimention; i++)
- {
- for(int j = 0; j < dimention; j++)
- {
- resultat[i][j] = calcul_element(matrice_a, matrice_b, dimention, i, j);
- }
- }
- }
- /*-------------------------------------------------------*/
- void matrice_puissance(int matrice[][], int resultat[][], int dimention, int puissance)
- {
- int matrice_b[dimention][dimention];
- if(puissance == 1)
- {
- affecter_matrice(resultat, matrice, dimention);
- }
- else if(puissance == 2)
- {
- prod(matrice, matrice, resultat, dimention);
- }
- else
- {
- prod(matrice, matrice, matrice_b, dimention);
- for(int i = 2; i < puissance; i++)
- {
- prod(matrice, matrice_b, resultat, dimention);
- affecter_matrice(matrice_b, resultat, dimention);
- }
- }
- }
- /*-------------------------------------------------------*/
- void affecter_matrice(int matrice_a[][], int matrice_b[][], int dimention)
- {
- for(int i = 0; i < dimention; i++)
- {
- for(int j = 0; j < dimention; j++)
- {
- matrice_a[i][j] = matrice_b[i][j];
- }
- }
- }
- int main(void)
- {
- int dimention, puissance;
- printf("veillez entrer la dimention de la matrice (n%cn) : ", 215);
- scanf("%d", &dimention);
- int matrice[dimention][dimention], resultat[dimention][dimention];
- remplir_matrice(matrice, dimention);
- printf("veillez entrer votre puissance : ");
- scanf("%d", &puissance);
- matrice_puissance(matrice, resultat, dimention, puissance);
- system("cls"); //clean the screen - nettoyer l'Γ©cran
- afficher_matrice(resultat, dimention);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement