fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. int n; // numero de elementos do array
  6. int index;
  7. int array[1000]; // array com capacidade para 1000 elementos;
  8.  
  9. // input 1
  10. if (scanf("%d", &n) != 1) exit(EXIT_FAILURE);
  11. if (n > 1000) exit(EXIT_FAILURE); // maximo de 1000 excedido
  12. if (n < 1) exit(EXIT_FAILURE); // minimo de 1
  13.  
  14. // ciclo n vezes (1o, 2o, 3o, ... numero da lista)
  15. for (index = 0; index < n; index++) {
  16. if (scanf("%d", array + index) != 1) exit(EXIT_FAILURE);
  17. }
  18.  
  19. // output dos n elementos do array
  20. printf("Array (%d elementos): %d", n, array[0]);
  21. for (index = 1; index < n; index++) printf(" %d", array[index]);
  22. puts("");
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 1792KB
stdin
5
42 13
-1
2013
6
stdout
Array (5 elementos): 42 13 -1 2013 6