Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int tableau1[100]; // création du tableau 1 100 cases une dimension
  6. int tableau2 [10][10];
  7. int tableau3 [10][3];
  8. int nombreRandom, MIN = 1, MAX = 1000; // nécessaire au nombre random
  9.  
  10. int main()
  11. {
  12. int code;
  13. int i;
  14. creation_tab1();// fait référence a une procédure
  15. tricroitableau(tableau1,100);
  16. /* for (i=0;i<100;i++){
  17.  
  18. printf("%d\n ",tableau1[i]);
  19. } */
  20.  
  21. copietableau();
  22. creation_tab3();
  23. tricroitableau3(tableau3,11);
  24. printf("telephone:\n");
  25. for (i=0;i<10;i++){
  26.  
  27. printf("%d ",tableau3[1+i][1]);
  28. printf("%d ",tableau3[1+i][2]);
  29. printf("%d\n",tableau3[1+i][3]);
  30. }
  31. printf("voici le tableau t2:\n\n");
  32. montrer_tab();
  33.  
  34. printf("rentrer votre code:\n");
  35. scanf("%d",&code);
  36.  
  37. for(i=0;i<11;i++){
  38. if (code == tableau3[i][3]){
  39. printf("deverouillage du coffre");
  40. break;
  41. }
  42. else if (i==10){
  43. printf("blocage du coffre");
  44. }
  45.  
  46.  
  47. }
  48.  
  49. }
  50.  
  51.  
  52. void creation_tab1(){
  53. srand(time(NULL)); // commande pour les nombre random
  54. int i;
  55. for (i=0; i<100;i++){
  56. nombreRandom = (rand() % (MAX - MIN + 1)) + MIN;
  57. tableau1[i] = nombreRandom;
  58. }
  59. }
  60.  
  61. void copietableau() {
  62. int i1;
  63. int valx=1;
  64. int valy=1;
  65. for(i1=0; i1<100 ;i1++){
  66. tableau2[valx][valy] = tableau1[i1];
  67. valx++;
  68. if (valx == 11){
  69. valx=1;
  70. valy++;
  71. }
  72. }
  73.  
  74. }
  75.  
  76. void creation_tab3() {
  77. int i,a,x,y;
  78. MAX = 10;
  79. srand(time(NULL));
  80. for (a=0; a<11;) {
  81. x = (rand() % (MAX - MIN + 1)) + MIN;
  82. y = (rand() % (MAX - MIN + 1)) + MIN;
  83. for (i=0;i<11;i++){
  84. if (y == tableau3[i][1] && x == tableau3[i][2]){
  85. i=11;
  86. }
  87. else if (i==10) {
  88. tableau3[a][1]= y;
  89. tableau3[a][2]= x;
  90. tableau3[a][3]= tableau2[x][y];
  91. a++;
  92. }
  93. }
  94. }
  95. }
  96.  
  97.  
  98. void tricroitableau(int tableau[], int tailletableau)
  99. {
  100. int valeurtemporaire, i, j;
  101.  
  102. for (i=0; i<tailletableau; i++)
  103. {
  104. for(j=i; j<tailletableau; j++)
  105. {
  106. if(tableau[j]<tableau[i])
  107.  
  108. {
  109. valeurtemporaire = tableau[i];
  110. tableau[i] = tableau[j];
  111. tableau[j] = valeurtemporaire;
  112. }
  113. }
  114.  
  115. }
  116. }
  117.  
  118. void tricroitableau3(int tableau[][3], int tailletableau) {
  119. int valeurtemporaire, i, j;
  120.  
  121. for (i=0; i<tailletableau; i++)
  122. {
  123. for(j=i; j<tailletableau; j++)
  124. {
  125. if(tableau[j][3]<tableau[i][3])
  126.  
  127. {
  128. valeurtemporaire = tableau[i][3];
  129. tableau[i][3] = tableau[j][3];
  130. tableau[j][3] = valeurtemporaire;
  131.  
  132. valeurtemporaire = tableau[i][2];
  133. tableau[i][2] = tableau[j][2];
  134. tableau[j][2] = valeurtemporaire;
  135.  
  136. valeurtemporaire = tableau[i][1];
  137. tableau[i][1] = tableau[j][1];
  138. tableau[j][1] = valeurtemporaire;
  139. }
  140. }
  141. }
  142. }
  143.  
  144. void montrer_tab(){
  145. int i1;
  146. int valx=1;
  147. int valy=1;
  148. for(i1=0; i1<94; i1++){
  149.  
  150. printf("[ %d ]",tableau2[valx][valy]);
  151. valy++;
  152. if (valy == 11){
  153. valy=1;
  154. valx++;
  155. printf("\n");
  156. }
  157. }
  158. printf("[ %d ][ %d ][ %d ][ %d ][ %d ][ %d ]\n",tableau1[49],tableau1[59],tableau1[69],tableau1[79],tableau1[89],tableau1[99]);
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement