Write a program that does the following: Dynamically allocates an array of 5 int
ID: 3687520 • Letter: W
Question
Write a program that does the following: Dynamically allocates an array of 5 integer elements Prompts the user for five integer values and stores them in the array. Prints the five integer values that were stored in the array. Prompts the user, asking by how much the array size should be expanded. Valid values are between 1 and 5. Expands the array by the requested amount (how?) Prompts the user for the remaining integers, so that the expanded array could be fully filled. Prints the contents of the entire array.Explanation / Answer
#include<iostream.h>
#include<stdlib.h>
int main()
{
int size=5,i,nsize;
int *array = new int[size];
for(i=0;i<size;i++)
{
cout<<"Enter number";
cin>>array[i];
}
for(i=0;i<size;i++)
{
cout<<array[i]<<endl;
}
cout<<"Enter how much array size must be expanded";
cin >> nsize;
for(i=size;i<size+nsize;i++)
{
cout<<"Enter number";
cin>>array[i];
}
for(i=0;i<(size+nsize);i++)
{
cout<<array[i]<<endl;
}
system("pause");
delete [] array;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.