Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Created by Jefferson
- #include <stdio.h>
- #include <stdlib.h>
- int lervalores
- int** alocarmatriz(int m, int n);
- int main(){
- int x, m, n;
- int **matriz;
- printf("diga-nos as dimensoes da matriz\n");
- scanf("%d %d", &m, &n);
- matriz = alocarmatriz(m, n);
- return 0;
- }
- int** alocarmatriz(int m, int n){
- int **matriz, x;
- //alocando memória para as linhas
- matriz = (int **) malloc(m*sizeof(int*));
- if(matriz == NULL){
- printf("Tem memoria nao. Pare de jogar e va estudar, pois o fim do periodo ta ai.");
- exit(1);
- }
- //alocando memória para as colunas
- for(x = 0; x < m; x++){
- matriz[x] = (int *) malloc(n*sizeof(int));
- if(matriz[x] == NULL){
- printf("Tem memoria nao. Pare de jogar e va estudar, pois o fim do periodo ta ai.");
- exit(1);
- }
- }
- return matriz;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement