Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main(){
- int elemento, i, j, x=0;
- printf("\nEntre com o numero de elementos do vetor: (4, 9, 16, 25, 36...)\n");
- printf("-> ");
- scanf("%d", &elemento);
- printf("\n");
- int l = pow(elemento,0.5), c = pow(elemento,0.5);
- int matriz[l][c], vetor[elemento];
- for(i=0; i<elemento; i++){
- printf("Entre com os elemento %d: ", i+1);
- scanf("%d", &vetor[i]);
- }
- for(i=0; i<l; i++){
- for(j=0; j<c; j++){
- matriz[i][j] = vetor[x];
- x++;
- }
- }
- printf("\nVetor:\n");
- for(i=0; i<elemento; i++){
- printf("%d ", vetor[i]);
- }
- printf("\n\nMatriz:\n");
- for(i=0; i<l; i++){
- for(j=0; j<c; j++){
- printf("%d ", matriz[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement