fork download
  1. //Ava Huntington CS1A Chapter 9 Homework P. 537, #1
  2. //
  3. /*******************************************************************************
  4.  * CREATE ARRAY SIZE
  5.  * _____________________________________________________________________________
  6.  * This simple program will accept an integer value and create a dynamically
  7.  * allocated array sized to the chosen integer.
  8.  * _____________________________________________________________________________
  9.  * INPUT
  10.  * array: array created by program
  11.  * number of elements: given number of elements
  12.  *
  13.  * OUTPUT
  14.  * end array: array created with given number of elements
  15.  ******************************************************************************/
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int main()
  20. {
  21. double *array;
  22. int numElms;
  23.  
  24.  
  25.  
  26. //Get number of elements in array
  27. cout << "How many elements should be in this array?" << endl;
  28. cin >> numElms;
  29.  
  30. //Dynamically allocate array
  31. array = new double[numElms];
  32.  
  33. //Loop for number of elements.
  34. for(int count = 0; count < numElms; count++)
  35. cout << count +1 << endl;
  36.  
  37. // Free dynamically allocated memory
  38. delete[] array;
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5280KB
stdin
12
stdout
How many elements should be in this array?
1
2
3
4
5
6
7
8
9
10
11
12