Advertisement
captainIBM

Untitled

May 5th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4.  
  5.  
  6. int main() {
  7.  
  8.  
  9.  
  10. int **plateau;
  11. int colonnes;
  12. int i = 0;
  13. int j = 0;
  14. int jeton = 0;
  15. int count = 1;
  16. int quit = 0;
  17.  
  18.  
  19.  
  20.  
  21. printf("Saisir le nombre de colonnes\n");
  22. scanf("%d",&colonnes);
  23.  
  24. if ((plateau = malloc(sizeof(int *) * colonnes)) == NULL)
  25. exit(0);
  26. for(i=0 ; i < colonnes ; i++){
  27. if ((plateau[i] = malloc(sizeof(int) * colonnes)) == NULL)
  28. exit(0);
  29. }
  30.  
  31. for(i=0;i<colonnes;i++){
  32. plateau[i][0] = i+1;
  33. for(j=1;j<colonnes + 1;j++){
  34. plateau[i][j] = 0;
  35. }
  36. }
  37. for(j=0;j<colonnes;j++){
  38. for(i=0;i<colonnes;i++){
  39. printf("| %d ",plateau[i][j]);
  40. }
  41. printf("\n");
  42. }
  43.  
  44.  
  45.  
  46. do {
  47.  
  48. /* ---------------------------------------------------------- */
  49.  
  50. printf("Joueur 1 :\n");
  51. scanf("%d",&jeton);
  52. system("cls");
  53.  
  54. for(i=0;i<colonnes;i++){
  55. for(j=1;i<colonnes + 1;j++){
  56. if(plateau[i][colonnes-j] == 0){
  57. count = j;
  58. break;
  59. }
  60. }
  61. if(plateau[i][0] == jeton){
  62. plateau[i][colonnes-count] = 1;
  63. }
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. for(j=0;j<colonnes;j++){
  71. for(i=0;i<colonnes;i++){
  72. printf("| %d ",plateau[i][j]);
  73. }
  74. printf("\n");
  75. }
  76.  
  77. } while (quit == 0);
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. system("PAUSE");
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement