Advertisement
J3st3rs_j0k3

pr4_5_cube

Dec 11th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define M 3
  4. #define N 3
  5. #define P 3
  6.  
  7. int main()
  8. {
  9.     int x, y, z, t, k = 0, n=0, cube[M][N][P];
  10.     for (x = 0; x < M; x++) {
  11.         for (y = 0; y < N; y++) {
  12.             for (z = 0; z < P; z++) {
  13.                 printf("Enter cube's color(%d)(%d)(%d) (0-red 1-green 2-blue ) = ", x, y, z);
  14.                 while(scanf("%d", &cube[x][y][z]) != 1){
  15.                     printf("Error. Enter digits!\n");
  16.                     fflush(stdin);
  17.                     printf("Enter cube's color(%d)(%d)(%d) (0-red 1-green 2-blue ) = ", x, y, z);
  18.                 }
  19.             }
  20.         }
  21.     }
  22.     for (x = 0; x < M; x++) {
  23.         for (y = 0; y < N; y++) {
  24.             for (z = 0; z < P; z++) {
  25.                 printf("%d ", cube[x][y][z]);
  26.             }
  27.             putchar('\n');
  28.         }
  29.         putchar('\n');
  30.     }
  31.     for (x = 0; x < M; x++) {
  32.         k = 0;
  33.         for (y = 0; y < N; y++) {
  34.              for (t = 0; t < P; t++) {
  35.                 if (cube[x][y][t] == cube[x][0][0]) {
  36.                     k++;
  37.                     if (k == (N*P))
  38.                         n++;
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.     for (y = 0; y < N; y++) {
  44.         k = 0;
  45.         for (z = 0;z < P; z++) {
  46.              for (t = 0;t < M;t++) {
  47.                 if (cube[t][y][z] == cube[0][y][0]) {
  48.                     k++;
  49.                     if (k == (M*P))
  50.                         n++;
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.     for (z = 0; z < P; z++) {
  56.         k = 0;
  57.         for (x = 0;x < M; x++) {
  58.              for (t = 0; t < N; t++) {
  59.                 if (cube[x][t][z] == cube[0][0][z]) {
  60.                     k++;
  61.                     if (k == (M*N))
  62.                         n++;
  63.                     }
  64.                 }
  65.             }
  66.         }
  67.     if (n) {
  68.         printf("Amount of layers of one color: %d\n",n);
  69.     }
  70.     else {
  71.         printf("There is no layers of one color\n");
  72.     }
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement