Q:

C++ program to declare, read and print dynamic integer array

belongs to collection: C++ programs on various topics

0

C++ program to declare, read and print dynamic integer array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the following program:

#include <iostream>

using namespace std;

int main()
{
	int *arr;	
	int i,n;
	
	cout<<"Enter total number of elements:";
	cin>>n;
	
	//declare memory
	arr=new int(n);
	
	cout<<"Input "<<n<<" elements"<<endl;
	for(i=0;i<n;i++)
	{
		cout<<"Input element "<<i+1<<": ";
		cin>>arr[i];
	}
	
	cout<<"Entered elements are: ";
	for(i=0;i<n;i++)
	{
		cout<<arr[i]<<" ";
	}
	cout<<endl;
	
	delete (arr);
	return 0;	
}

Output

 
Enter total number of elements:5
Input 5 elements
Input element 1: 10 
Input element 2: 20 
Input element 3: 30 
Input element 4: 40 
Input element 5: 50 
Entered elements are: 10 20 30 40 50 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ programs on various topics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ program to declare an integer variable dynamic... >>
<< C++ - Print the string character by character usin...