Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char** argv) {
  5. //definimos el tipo de dato Matriz
  6. typedef struct{
  7. int i;
  8. int j;
  9. int *datos;
  10. }Matriz;
  11.  
  12. Matriz *m;
  13. int k=0;
  14. int l=0;
  15. int fil, col;
  16.  
  17.  
  18. //pedimos los datos al usuario y los escaneamos
  19. printf("Número de filas:");
  20. fflush(stdout);
  21. scanf("%d",&fil);
  22. printf("Número de columnas:");
  23. fflush(stdout);
  24. scanf("%d", &col);
  25. m = (Matriz*)malloc(sizeof(Matriz));
  26. m->i=fil;
  27. m->j=col;
  28. m->datos = (int*)malloc(m->i*m->j*sizeof(int*));
  29. for(k = 0 ; k<fil; k++){
  30. for(l=0; l<col; l++){
  31. printf("Elemento %d%d", k, l);
  32. fflush(stdout);
  33. //scanf("%d",&(m[k*col +l]));
  34. scanf("%d",&(m[k*col +l]));
  35. }
  36. }
  37. //imprimimos la matriz
  38. for(k = 0; k < fil; k++){
  39. printf("n");
  40. for(l = 0; l < col; l++){
  41. printf("%d ", *(m + k*col + l));
  42.  
  43. }
  44. }
  45.  
  46. return (EXIT_SUCCESS);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement