Program to print Array Element in Reverse Order

//Code for Program to print array element in reverse order in C Programming

#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *ptr,i,n;
    clrscr();
    printf("Enter the no of elements:");
    scanf("%d",&n);
    ptr=(int *)malloc(sizeof(int)*n);
    if(ptr==NULL)
    {
        printf("Not enough memory");
        exit(1);
    }
    for(i=0; i<n; i++)
    {
        printf("Enter %d element : ",i+1);
        scanf("%d",&ptr[i]);
    }
    printf("Array in original order\n");
    for(i=0; i<n; i++)
    {
        printf("%d\n",ptr[i]);
    }
    printf("Array in reverse order\n");
    for(i=n-1; i>=0; i--)
    {
        printf("%d\n",ptr[i]);
    }
    getch();
    return 0;
}

Post a Comment

0 Comments