I would like to generate a vector where its next position element is added by 1. For example: be vetor[3]
, I'd like v[0] = 1
and v[1] = v[0] + 1
, v[2] = v[1] + 1
, and so on. How would you do that?
Follow my code for now:
#include <stdio.h>
#include<stdlib.h>
int main(){
int N, M, i;
int *v;
printf ("Entre com N: ");
scanf ("%d", &N);
printf ("Entre com M: ");
scanf ("%d", &M);
v = (int *)malloc(M * sizeof (int));
v[0] = 1;
for (i=0; i < M; ++i){
v[i]++;
printf ("%d ", v[i]);
}
}