Untitled

 avatar
unknown
plain_text
4 years ago
935 B
3
Indexable
#include<iostream>
#include<conio.h>
using namespace std;

void  inputArrayExtend() {
    int maxSize = 2;
    int* p = new int[maxSize];
    for (int i = 0; true; i++) {
        if (i > 1) {
            cout << "Qua so luong phan tu" << endl;
            break;
        }
        cout << " Nhap phan tu thu " << i + 1 << ": ";
        cin >> *(p + i);
        cout << endl;   
        if (*(p + i) > 9 || *(p + i) < 0) { i--; }

    }
    int* q = new int[maxSize * 2];
    for (int i = 0; i < 2; i++) {
        q[i] = p[i];
    };

    for (int i = 2; i == 2; i++) {
        cout << "nhap lai phan tu 3:";
        cin >> *(q + 2);
        if (*(q + 2) > 9 || *(q + 2) < 0) { i--; }
    };
    delete []p;
    p = q;
    for (int i = 0; i < maxSize*2 - 1; i++) {
        cout << "Phan tu thu " << i + 1 << " :" << *(p + i) << endl;
    }
}
  int main(){
      inputArrayExtend();
      return 0;
}
Editor is loading...