Skip to content

Instantly share code, notes, and snippets.

@itacirgabral
Created December 6, 2018 01:27
Show Gist options
  • Save itacirgabral/3ba2931c0373f03341200d4a2d5aa2c5 to your computer and use it in GitHub Desktop.
Save itacirgabral/3ba2931c0373f03341200d4a2d5aa2c5 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
void main() {
int* vet = NULL;
int i = 0;
int soma = 0;
vet = (int*) malloc (1 * sizeof(int));
do {
printf("idade[%d] = ", i);
scanf(" %d", &vet[i]);
soma += vet[i];
vet = (int*) realloc (vet, (i + 1) * sizeof(int));
i++;
} while (vet[i-1] > -1);
printf("soma = %d\n", soma);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment