fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. size_t count=0,capacity=4;
  8. int *tab=new int[capacity];
  9. while(true)
  10. {
  11. cout<<"\rPodaj liczbe nr "<<(count+1)<<": ";
  12. int value;
  13. cin>>value;
  14. if(value<0) break;
  15. if(count>=capacity)
  16. {
  17. capacity+=4;
  18. int *tmp=new int[capacity];
  19. memcpy(tmp,tab,count*sizeof(int));
  20. delete[] tab;
  21. tab=tmp;
  22. }
  23. tab[count++]=value;
  24. }
  25. cout<<endl;
  26. for(int i=0;i<count;++i) cout<<tab[i]<<", ";
  27. delete[] tab;
  28. return 0;
  29. }
Success #stdin #stdout 0s 3432KB
stdin
1
2
3
4
5
6
7
8
9
-1
stdout
Podaj liczbe nr 1: 
Podaj liczbe nr 2: 
Podaj liczbe nr 3: 
Podaj liczbe nr 4: 
Podaj liczbe nr 5: 
Podaj liczbe nr 6: 
Podaj liczbe nr 7: 
Podaj liczbe nr 8: 
Podaj liczbe nr 9: 
Podaj liczbe nr 10: 
1, 2, 3, 4, 5, 6, 7, 8, 9,