Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(){
  6.     int *vettore;
  7.     int n=0, contatore=1;
  8.    
  9.     vettore = malloc(1*sizeof(int));
  10.     printf("inserisci il numero: ");
  11.     scanf("%d", &n);
  12.     vettore[0] = n;
  13.    
  14.     while (n != -1){
  15.         printf("inserisci il numero: ");
  16.         scanf("%d", &n);
  17.         contatore++;
  18.         vettore = realloc(vettore, contatore*sizeof(int));
  19.         vettore[contatore] = n;
  20.      
  21.     }
  22.    
  23.     for (int i=0; i<10; i++) {
  24.         printf("%d\n", vettore[i]);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement