Accept and print numbers using pointers

Q. Write a C++ program to accept the set of 5 numbers and print the numbers using pointer.

Answer:

Following program is accepting and displaying the set of 5 numbers using pointer.

#include<iostream>
using namespace std;
int main()
{
        int *p, i;
        p = new int [5];
        cout<<"\n Enter 5 Numbers : \n";
        for(i=0; i<=4; i++)
        {
                cout<<" ";
                cin>>*(p+i);
        }
        cout<<"\n Entered Numbers are : \n";
        for(i=0;i<=4;i++)
        {
                cout<<" ";
                cout<<*(p+i)<<"\t";
        }
        return 0;
}


Output:

insert print numbers