int main() { int n; cout << "Enter size of array: "; cin >> n; int *arr = new int[n]; // allocating memory for array for(int i=0; i
In this example, the user is prompted to enter the size of the array at runtime, and memory is allocated for the array using the 'new' operator. The user can then access and modify the array elements as desired, before deallocating the memory using the 'delete' operator.
Example 2:vector> matrix; int rows, cols; cout << "Enter number of rows: "; cin >> rows; cout << "Enter number of columns: "; cin >> cols; matrix.resize(rows, vector (cols)); for(int i=0; i In this example, a 2D vector is created with the size of the matrix determined at runtime by the user. The user can then access and modify the matrix elements as desired. The package library used in these examples is the standard C++ library.