Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char** argv) {
- //definimos el tipo de dato Matriz
- typedef struct{
- int i;
- int j;
- int *datos;
- }Matriz;
- Matriz *m;
- int k=0;
- int l=0;
- int fil, col;
- //pedimos los datos al usuario y los escaneamos
- printf("Número de filas:");
- fflush(stdout);
- scanf("%d",&fil);
- printf("Número de columnas:");
- fflush(stdout);
- scanf("%d", &col);
- m = (Matriz*)malloc(sizeof(Matriz));
- m->i=fil;
- m->j=col;
- m->datos = (int*)malloc(m->i*m->j*sizeof(int*));
- for(k = 0 ; k<fil; k++){
- for(l=0; l<col; l++){
- printf("Elemento %d%d", k, l);
- fflush(stdout);
- //scanf("%d",&(m[k*col +l]));
- scanf("%d",&(m[k*col +l]));
- }
- }
- //imprimimos la matriz
- for(k = 0; k < fil; k++){
- printf("n");
- for(l = 0; l < col; l++){
- printf("%d ", *(m + k*col + l));
- }
- }
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement