Question #37365

Write code that dynamically allocates an array of 20 integers, then uses a loop to allow the user to enter values for each element of the array

Expert's answer

#include <iostream> #include <conio.h>using namespace std;int main () {          int* array = new int [20];          for (int i=0; i<20; i++)          {                     cout<<"Enter the "<<i+1<<" elemet of the array: ";                     cin>>array[i];          }      cout<<"So, this is the array :"<<endl;          for (int i=0; i<20; i++)         {                     cout<<array[i]<<" ";         }             delete [] array;    _getch();        return 0;}
LATEST TUTORIALS
APPROVED BY CLIENTS