Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- // pointer program. creeaza o matrice cu un singur for
- void CitireAfisare(int *p, int n, int m, int sect) {
- int *init;
- init = p;
- int lungime = n*m;
- int k;
- // am un vector -> matrice k -> (i,j) k/coloana, k%coloana
- for (k = 0; k < sect; k++)
- for (int i = 0; i < lungime; i++) {
- printf("matrice[%d][%d][%d]= ", k, i / m, i%m);
- scanf_s("%d", p);
- p++;
- }
- int i;
- p = init; // 1 2 3 4 5 6 7 8 9
- printf("\nAfisare matrice 3D:\n");
- for (k = 0; k < sect; k++) {
- for (i = 0; i < lungime; i++) {
- if (i%m == 0) {
- printf("\n");
- for (int x = 0; x < k; x++)
- printf(" ");
- }
- printf("%d ", *p);
- p++;
- }
- }
- }
- int * Alocare(int n, int m, int sect) {
- int *p;
- int lungime = n*m*sect;
- if ((p = (int *)malloc(sizeof(int)*lungime)) == NULL) { // ( (p=)==NULL)
- printf("nu s-a gasit in memorie");
- _getch();
- exit(0);
- }
- return p;
- }
- void main() {
- int *p;
- int n, m, sect, lungime;
- printf("Introduceti nr de sectiuni: ");
- scanf_s("%d", §);
- printf("Introduceti nr de linii ale matricei: ");
- scanf_s("%d", &n);
- printf("Introduceti nr de coloane ale matricei:");
- scanf_s("%d", &m);
- lungime = n*m;
- p = Alocare(n, m, sect);
- CitireAfisare(p, n, m, sect);
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement