Vectors, pointers, and storage in memory [closed]

-5

I need to solve an exercise where I need to use pointers, vectors and memory storage:

  

Create a vector with n elements, where each vector position   will match a pointer to a value of type float . Do it   read n values and store them in memory.

I do not think it's very complex, but I'm still studying the subject and it would be nice to have this exercise solved to see how things work.

    
asked by anonymous 21.12.2015 / 16:24

1 answer

1

So I understand that.

#include <stdio.h>
#include <stdlib.h>

    int main () {
       int  n, i;
       float *v; // Declaração do vetor
       scanf ("%d", &n); 
       v = malloc (n * sizeof (float)); // Alocação do vetor em n elementos
       for (i = 0; i < n; i++) scanf ("%f", &v[i]); // Leitura e armazenamento dos valores na memoria
       for (i = 0; i < n; i++) printf ("%f ", v[i]); // Teste
       return 0;
    }
    
21.12.2015 / 16:54