Advertisement
michael_xgrind

Matriz -> Vetor

Jul 27th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(){
  5.     int elemento, i, j, x=0;
  6.  
  7.     printf("\nEntre com o numero de elementos do vetor: (4, 9, 16, 25, 36...)\n");
  8.     printf("-> ");
  9.     scanf("%d", &elemento);
  10.     printf("\n");
  11.  
  12.  
  13.     int l = pow(elemento,0.5), c = pow(elemento,0.5);
  14.     int matriz[l][c], vetor[elemento];
  15.  
  16.     for(i=0; i<elemento; i++){
  17.         printf("Entre com os elemento %d: ", i+1);
  18.         scanf("%d", &vetor[i]);
  19.     }
  20.  
  21.     for(i=0; i<l; i++){
  22.         for(j=0; j<c; j++){
  23.             matriz[i][j] = vetor[x];
  24.             x++;
  25.         }
  26.     }
  27.  
  28.     printf("\nVetor:\n");
  29.     for(i=0; i<elemento; i++){
  30.         printf("%d ", vetor[i]);
  31.     }
  32.  
  33.     printf("\n\nMatriz:\n");
  34.     for(i=0; i<l; i++){
  35.         for(j=0; j<c; j++){
  36.             printf("%d ", matriz[i][j]);
  37.         }
  38.         printf("\n");
  39.     }
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement