Write a c program to reverse an array elements using dynamic memory allocation.


#include 
void REVERSE(int *ptr1, int *ptr2, int n);
void main()
{
int X[30], m, i;
clrscr();
printf("\n\n\n\tEnter the size of Array (Less than 30):");
scanf("%d",&m);
if ((m > 30) || (m < 2))
{
printf("\n\n\t\tERROR !!!!!!");
printf("\n\t\tENTER SIZE WITHIN GIEVEN FIELDS....TRY AGAIN");
getch();
exit(0);
}
clrscr();
printf("\n\n\n\tEnter the elements of Array :");
for(i=0;i{
printf("\nElement %d:",i+1);
scanf("%d",&X[i]);
}
REVERSE(X,X,m);
printf("\n\n\n\n\tThe Reversed Array is:\n");
for(i=0;iprintf("\n\t\tElement %d: %d",i+1,X[i]);
getch();
}
void REVERSE(int *ptr1, int *ptr2, int n)
{
int *temp=NULL;
int i;
for(i=0;i

for(i=0,ptr2--; i<(n/2); i++,ptr1++,ptr2--)
{
*temp=*ptr1;
*ptr1=*ptr2;
*ptr2=*temp;
}
}
/*------------------------------output---------------------------

Enter the size of Array (Less than 30):5

Enter the elements of Array :
Element 1:2

Element 2:5

Element 3:8

Element 4:1

Element 5:2

        The Reversed Array is:

                Element 1: 2
                Element 2: 1
                Element 3: 8
                Element 4: 5
                Element 5: 2 */
                                                 
Write a c program to reverse an array elements using dynamic memory allocation. Write a c program to reverse an array elements using dynamic memory allocation. Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.