Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #define M 100
- #define N 100
- void AlocacaoMemoria()
- {
- int i;
- int *v[M];
- for(i=0; i<M; i++)
- {
- printf("\n%d", i);
- v[i] = (int *) malloc(M*N*sizeof(int));
- if ( v[i] )
- Sleep( 100 );
- }
- for(i=0; i<M; i++)
- {
- printf("\n%d", i);
- if ( v[i] )
- {
- free( v[i] );
- Sleep( 100 );
- }
- }
- }
- void Vetor()
- {
- int i;
- int *p = (int *) malloc(M*sizeof(int));
- if ( !p )
- return;
- for(i=0; i<M; i++)
- {
- p[i] = i;
- // Sleep( 10 );
- }
- for(i=0; i<M; i++)
- {
- printf("\n%d = %d", i, p[i]);
- Sleep( 10 );
- }
- free( p );
- }
- void LeMatrizInteiros(int nLinha, int nColuna, int matriz[nLinha][nColuna])
- {
- int i, j;
- for(i=0; i<M; i++)
- for(j=0; j<N; j++)
- {
- matriz[i][j] = i*j;
- // Sleep( 10 );
- }
- }
- void EscreveMatrizInteiros(int nLinha, int nColuna, int matriz[nLinha][nColuna])
- {
- int i, j;
- for(i=0; i<M; i++)
- for(j=0; j<N; j++)
- {
- printf("\n%d * %d = %d", i, j, matriz[i][j]);
- Sleep( 10 );
- }
- }
- void Matriz()
- {
- int *p = (int *) malloc(M*N*sizeof(int));
- if ( !p )
- return;
- LeMatrizInteiros(M, N, p);
- EscreveMatrizInteiros(M, N, p);
- free( p );
- }
- int main()
- {
- AlocacaoMemoria();
- Vetor();
- Matriz();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement