Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define M 3
- #define N 3
- #define P 3
- int main()
- {
- int x, y, z, t, k = 0, n=0, cube[M][N][P];
- for (x = 0; x < M; x++) {
- for (y = 0; y < N; y++) {
- for (z = 0; z < P; z++) {
- printf("Enter cube's color(%d)(%d)(%d) (0-red 1-green 2-blue ) = ", x, y, z);
- while(scanf("%d", &cube[x][y][z]) != 1){
- printf("Error. Enter digits!\n");
- fflush(stdin);
- printf("Enter cube's color(%d)(%d)(%d) (0-red 1-green 2-blue ) = ", x, y, z);
- }
- }
- }
- }
- for (x = 0; x < M; x++) {
- for (y = 0; y < N; y++) {
- for (z = 0; z < P; z++) {
- printf("%d ", cube[x][y][z]);
- }
- putchar('\n');
- }
- putchar('\n');
- }
- for (x = 0; x < M; x++) {
- k = 0;
- for (y = 0; y < N; y++) {
- for (t = 0; t < P; t++) {
- if (cube[x][y][t] == cube[x][0][0]) {
- k++;
- if (k == (N*P))
- n++;
- }
- }
- }
- }
- for (y = 0; y < N; y++) {
- k = 0;
- for (z = 0;z < P; z++) {
- for (t = 0;t < M;t++) {
- if (cube[t][y][z] == cube[0][y][0]) {
- k++;
- if (k == (M*P))
- n++;
- }
- }
- }
- }
- for (z = 0; z < P; z++) {
- k = 0;
- for (x = 0;x < M; x++) {
- for (t = 0; t < N; t++) {
- if (cube[x][t][z] == cube[0][0][z]) {
- k++;
- if (k == (M*N))
- n++;
- }
- }
- }
- }
- if (n) {
- printf("Amount of layers of one color: %d\n",n);
- }
- else {
- printf("There is no layers of one color\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement