Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int* agregar(int* pV, int &n, int v) {
- int* pAux = new int[n+1];
- for (int i = 0; i < n; i++)//Pasando todos los elementos del vector antiguo al nuevo
- pAux[i] = pV[i];
- pAux[n] = v;//Aumentando el nuevo elemento al vector
- n++;
- delete pV;
- return pAux;
- }
- void mostrar(int* pV, int n) {
- system("cls");
- for (short i = 0; i < n; i++)
- cout << pV[i] << " ";
- system("pause>0");
- }
- int main() {
- int* pVec;
- int cant = 0, valor;
- while (true) {
- cout << "Ingrese un valor: "; cin >> valor;
- pVec = agregar(pVec, cant, valor);
- mostrar(pVec, cant);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement