-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2-MatricesYRealloc.c
More file actions
52 lines (40 loc) · 839 Bytes
/
Copy path2-MatricesYRealloc.c
File metadata and controls
52 lines (40 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
int **inicializarMatriz(int N, int M);
void cargarMatriz(int **A, int N, int M);
void mostrarMatriz(int **A, int N, int M);
int main(int argc, char *argv[]) {
int **A;
int N = 3, M = 3;
A = inicializarMatriz(N, M);
cargarMatriz(A, N, M);
mostrarMatriz(A, N, M);
return 0;
}
int **inicializarMatriz(int N, int M){
int **A;
int i;
A = (int **)calloc(N, sizeof(int *));
for(i=0; i<N; i++){
A[i] = (int *)calloc(M, sizeof(int));
}
return A;
}
void cargarMatriz(int **A, int N, int M){
int i, j;
for(i=0; i<N; i++){
for(j=0; j<M; j++){
printf("Ingrese elemento (%d, %d): ", i, j);
scanf("%d", &A[i][j]);
}
}
}
void mostrarMatriz(int **A, int N, int M){
int i, j;
for(i=0; i<N; i++){
for(j=0; j<M; j++){
printf("%d\t", A[i][j]);
}
printf("\n");
}
}