C Program to Reverse Elements in Array

include

int main()
{
int n, i, j, *p, a[10], b[10];
printf(“Enter the number of elements :: “);
scanf(“%d”, &n);

printf("Enter the elements : ");
for(i = 0; i < n; i++)
{
    scanf("%d", &a[i]);
}

//REVERSING THE ARRAY

p=a;
for(i = 0, j = n-1; i < n; i++, j--)
{
    b[i] = *(p+j);
}
printf("The reversed array :: ");

for(i = 0; i < n; i++)
    printf("%d  ", b[i]);

printf("\n");
return 0;

}

OUTPUT:
Enter the number of elements :: 6
Enter the elements : 10 20 30 40 50 60
The reversed array :: 60 50 40 30 20 10

Leave a Reply

Your email address will not be published.