Write a function that reverses the elements of an array in place. The function must accept only one pointer value and return void.
#include<iostream.h>
#include<conio.h>
class reverse
{
public:
int n;
reverse();
void rev(int* a);
};
reverse::reverse()
{
cout<<"enter the number of elements you
want to store"<<endl;
cin>>n;
}
void reverse::rev(int* a)
{
cout<<"The reversed array is "<<endl;
for(int i=n-1;i>=0;i--)
cout<<a[i]<<endl;
}
int main()
{
clrscr();
reverse obj;
int* a1 ;
a1=new int[obj.n];
cout<<"enter the elements of the array
"<<endl;
for(int i=0;i<obj.n;i++)
cin>>a1[i];
obj.rev(a1);
getch();
return 1;
}
Output:-
Comments
Post a Comment