Advertisement
michael_xgrind

Untitled

Jul 26th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(){
  5.     int i, j, linhas, colunas, ve;
  6.     int *pLinhas, *pColunas, *pVetor;
  7.     int matriz[3][3], vetor[3];
  8.  
  9.     printf("Digite o numero de linhas: ");
  10.     scanf("%d", &linhas);
  11.     printf("Digite o numero de colunas: ");
  12.     scanf("%d", &colunas);
  13.  
  14.     pLinhas = (int*) malloc(linhas* sizeof(int));
  15.     pColunas = (int*) malloc(colunas* sizeof(int));
  16.  
  17.   //  int matriz[linhas][colunas], vetor[linhas*colunas];
  18.  
  19.     for(i=0; i<linhas; i++){
  20.         for(j=0; j<colunas; j++){
  21.             scanf("%d", &matriz[i][j]);
  22.         }
  23.     }
  24.  
  25.     for(j=0; j<linhas; j++){
  26.         vetor[j] = matriz[0][j];
  27.     }
  28.     for(j=linhas; j<linhas*colunas; j++){
  29.         vetor[j] = matriz[0][j];
  30.     }
  31.  
  32.     printf("\nMatriz:\n");
  33.     for(i=0; i<linhas; i++){
  34.         for(j=0; j<colunas; j++){
  35.             printf("%d ", matriz[i][j]);
  36.         }
  37.         printf("\n");
  38.     }
  39.  
  40.     printf("\nVetor:\n");
  41.     for(i=0; i<linhas*colunas; i++)
  42.         printf("%d ", vetor[i]);
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement