fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // Size of the array
  6. int size;
  7. cout << "Enter the size of the array: ";
  8. cin >> size;
  9.  
  10. // Dynamically allocate an array
  11. int* arr = new int[size];
  12.  
  13. // Input values into the array
  14. cout << "Enter " << size << " elements:" << endl;
  15. for (int i = 0; i < size; ++i) {
  16. cin >> arr[i];
  17. }
  18.  
  19. // Print values from the array
  20. cout << "Array elements are:" << endl;
  21. for (int i = 0; i < size; ++i) {
  22. cout << arr[i] << " ";
  23. }
  24. cout << endl;
  25.  
  26. // Deallocate memory to avoid memory leaks
  27. delete[] arr;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5284KB
stdin
222
stdout
Enter the size of the array: Enter 222 elements:
Array elements are:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0