Write a c++ program that makes a dynamic array and uses an integer to checks its size. Enter numbers in it until the user presses 4. Create another array and copy the contents of first array into the new array and delete the memory of 1st array. Also print as you insert the values.
#include<iostream>
using namespace std;
int main()
{
int size,n,i,a,m;
int finA[17]={};
int initA[]={10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170};
n = sizeof(initA)/sizeof(initA[0]);
cout << "The size of the array is: " << n<<endl;
cout<<"Input the elements of the first array: "<<endl;
for(i=0;i<n;i++)
{
cin>>a;
if(a==4){
break;
}
}
for(m=0;m<n;m++)
{
finA[m]=initA[m];
}
cout<<"The final array is\n";
for(m=0;m<=n;m++)
cout<<finA[m]<<" "<<endl;
delete [] initA;
return 0;
}
Comments
Leave a comment