Here is a C++ program to dynamically store n elements in an array
SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
int *a,n;
cout<<"How many elements to be stored ";
cin>>n;
a=new int[n];
cout<<"Enter elements ";
for(int i=0;i<n;i++)
cin>>a[i];
cout<<"You have entered : ";
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
return 0;
}
using namespace std;
int main()
{
int *a,n;
cout<<"How many elements to be stored ";
cin>>n;
a=new int[n];
cout<<"Enter elements ";
for(int i=0;i<n;i++)
cin>>a[i];
cout<<"You have entered : ";
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment