1 2 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
| #include <stdio.h>
#include <stdlib.h>
void rotate_mat(int mat[4][4],int res[4][4],unsigned int rot)
{
int liste1[12]={1,2,3,4,8,12,16,15,14,13,9,5};
int liste2[4]={6,7,11,10};
int temporaire1[12]={0,0,0,0,0,0,0,0,0,0,0,0};
int temporaire2[4]={0,0,0,0};
int rotation1=rot%12;
int rotation2=rot%4;
for (int i=0;i<rotation1;i++)
{
temporaire1[11-i]=liste1[rotation1-i-1];
}
for (int i=0;i<12-rotation1;i++)
{
liste1[i]=liste1[rotation1+i];
}
for (int i=12-rotation1; i<12;i++)
{
liste1[i]=temporaire1[i];
}
for (int i=0;i<rotation2;i++)
{
temporaire2[3-i]=liste2[rotation2-i-1];
}
for(int i=0;i<4-rotation2;i++)
{
liste2[i]=liste2[rotation2+i];
}
for(int i=4-rotation2;i<4;i++)
{
liste2[i]=temporaire2[i];
}
for(int i=0;i<4;i++)
{
res[0][i]=liste1[i];
res[3][i]=liste1[9-i];
}
res[1][0]=liste1[11];
res[1][1]=liste2[0];
res[1][2]=liste2[1];
res[1][3]=liste1[4];
res[2][0]=liste1[10];
res[2][1]=liste2[3];
res[2][2]=liste2[2];
res[2][3]=liste1[5];
for (int i=0;i<4 ; i++)
{
for(int j=0;j<4;j++)
{
printf("%d\n", res[i][j]);
}
}
return 0;
}
int main()
{
int mat[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
int resultat[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
unsigned int n=0;
printf("Valeur de la rotation :");
scanf("%d",&n);
rotate_mat(mat[4][4],resultat[4][4],n);
return 0;
} |
Partager