Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int* num = NULL;
- int tam = 0;
- int fim = 1;
- int ent;
- while (fim != 0) {
- printf("\ndigite um numero: ");
- scanf("%d", &ent);
- if (ent == 0) {
- fim = 0;
- } else {
- num = realloc(num, (tam + 1) * sizeof(int));
- if (num == NULL) {
- printf("Memory allocation failed.\n");
- return 1;
- }
- num[tam] = ent;
- tam++;
- }
- }
- printf("\no que vc digitou: ");
- for (int i = 0; i < tam; i++) {
- printf("\n%d", num[i]);
- }
- free(num);
- return 0;
- }
Add Comment
Please, Sign In to add comment