Created
February 27, 2020 09:32
-
-
Save Blightwidow/72023e9f1adc5b73cb67fedfcf7c230f to your computer and use it in GitHub Desktop.
matrix.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
unsigned int aaa, bbb; | |
int a[3][3][3]; | |
int * vp[3]; | |
int * pp; | |
int j, k; | |
char rasp = '1'; | |
void | |
main() { | |
clrscr(); | |
/* Here we are creating a martix of 3 by 3 by 3 | |
* full of 0, like: | |
* * - * - * | |
* * - * - * | |
* * - * - * * | |
* | | | * | |
* * - * - * * | |
* | | | * | |
* * - * - * | |
*/ | |
for (int i = 0; i < 3; i++) | |
for (j = 1; j < 3; j++) | |
for (k = 0; k < 3; k++) | |
a[i][k][j] = 0; | |
/* Here we are extracting the pointer | |
* adress of the beginning of line i | |
*/ | |
for (i = 0; i < 3; i++) | |
vp[i] = & a[i][0][0]; | |
/* While the rasp buffer does not contains space | |
*/ | |
while (rasp != ' ') { | |
/* We ask the user a coordinate i. You would want | |
* to check that the i value put by the user is | |
* less or equal than the maximum index of 2 | |
*/ | |
printf("\nintroduceti coordonatele:\n "); | |
printf("\ncoordonata i : "); | |
scanf("%d", & i); | |
i--; | |
/* We ask the user a coordinate j. You would want | |
* to check that the i value put by the user is | |
* less or equal than the maximum index of 2 | |
*/ | |
printf("coordonata j : "); | |
scanf("%d", & j); | |
j--; | |
/* We ask the user a coordinate k. You would want | |
* to check that the i value put by the user is | |
* less or equal than the maximum index of 2 | |
*/ | |
printf("coordonata k : "); | |
scanf("%d", & k); | |
k--; | |
/* From the address of the beginning of the lines | |
* in VP, we then extract the memory address of | |
* the desired value | |
*/ | |
aaa = vp[i]; | |
bbb = vp[i]; | |
aaa += (j * 3 + k) * 2; | |
bbb += (j * 3 + k) * 2; | |
pp = (int * )(aaa, bbb); | |
/* We ask for a value to put at this adress | |
*/ | |
printf("\ndati elementul: "); | |
scanf("%d", pp); | |
/* Then we ask if the user wants to modify more data. | |
* Pressing space will stop the loop | |
* Pressing anything esl will allow him to modify a new adress value | |
*/ | |
printf("\nContinuati introducerea? [pentru nu,tastati spatiu]: "); | |
fflush(stdin); | |
scanf("%c", & rasp); | |
} | |
/* Now the use is out of the loop and you display | |
* the resulting matrix | |
*/ | |
for (i = 0; i < 3; i++) { | |
for (j = 0; j < 3; j++) { | |
for (k = 0; k < 3; k++) | |
printf(" %d ", a[i][j][k]); | |
printf("\n"); | |
} | |
printf("\n*******\n"); | |
} | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment