Advertisement
JCLC

Untitled

Jun 10th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. //Created by Jefferson
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int lervalores
  7. int** alocarmatriz(int m, int n);
  8.  
  9.  
  10. int main(){
  11.     int x, m, n;
  12.     int **matriz;
  13.  
  14.     printf("diga-nos as dimensoes da matriz\n");
  15.     scanf("%d %d", &m, &n);
  16.     matriz = alocarmatriz(m, n);
  17.  
  18. return 0;
  19. }
  20.  
  21. int** alocarmatriz(int m, int n){
  22.     int **matriz, x;
  23.  
  24.     //alocando memória para as linhas
  25.     matriz = (int **) malloc(m*sizeof(int*));
  26.     if(matriz == NULL){
  27.         printf("Tem memoria nao. Pare de jogar e va estudar, pois o fim do periodo ta ai.");
  28.         exit(1);
  29.     }
  30.     //alocando memória para as colunas
  31.     for(x = 0; x < m; x++){
  32.         matriz[x] = (int *) malloc(n*sizeof(int));
  33.         if(matriz[x] == NULL){
  34.             printf("Tem memoria nao. Pare de jogar e va estudar, pois o fim do periodo ta ai.");
  35.             exit(1);
  36.         }          
  37.     }  
  38.  
  39.     return matriz;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement