Advertisement
bertao

exemplo do professor

May 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. #define M 100
  6. #define N 100
  7.  
  8. void AlocacaoMemoria()
  9. {
  10. int i;
  11. int *v[M];
  12.  
  13. for(i=0; i<M; i++)
  14. {
  15. printf("\n%d", i);
  16. v[i] = (int *) malloc(M*N*sizeof(int));
  17.  
  18. if ( v[i] )
  19. Sleep( 100 );
  20. }
  21.  
  22. for(i=0; i<M; i++)
  23. {
  24. printf("\n%d", i);
  25.  
  26. if ( v[i] )
  27. {
  28. free( v[i] );
  29. Sleep( 100 );
  30. }
  31. }
  32. }
  33.  
  34. void Vetor()
  35. {
  36. int i;
  37. int *p = (int *) malloc(M*sizeof(int));
  38.  
  39. if ( !p )
  40. return;
  41.  
  42. for(i=0; i<M; i++)
  43. {
  44. p[i] = i;
  45. // Sleep( 10 );
  46. }
  47.  
  48. for(i=0; i<M; i++)
  49. {
  50. printf("\n%d = %d", i, p[i]);
  51. Sleep( 10 );
  52. }
  53.  
  54. free( p );
  55. }
  56.  
  57. void LeMatrizInteiros(int nLinha, int nColuna, int matriz[nLinha][nColuna])
  58. {
  59. int i, j;
  60.  
  61. for(i=0; i<M; i++)
  62. for(j=0; j<N; j++)
  63. {
  64. matriz[i][j] = i*j;
  65. // Sleep( 10 );
  66. }
  67. }
  68.  
  69. void EscreveMatrizInteiros(int nLinha, int nColuna, int matriz[nLinha][nColuna])
  70. {
  71. int i, j;
  72.  
  73. for(i=0; i<M; i++)
  74. for(j=0; j<N; j++)
  75. {
  76. printf("\n%d * %d = %d", i, j, matriz[i][j]);
  77. Sleep( 10 );
  78. }
  79. }
  80.  
  81. void Matriz()
  82. {
  83.  
  84. int *p = (int *) malloc(M*N*sizeof(int));
  85.  
  86. if ( !p )
  87. return;
  88.  
  89. LeMatrizInteiros(M, N, p);
  90. EscreveMatrizInteiros(M, N, p);
  91.  
  92. free( p );
  93. }
  94.  
  95. int main()
  96. {
  97. AlocacaoMemoria();
  98. Vetor();
  99. Matriz();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement