Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to print array element in reverse order

Posted By: Volker Fischer     Category: C Programming     Views: 15834

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;
}
  
Share: 


Didn't find what you were looking for? Find more on Program to print array element in reverse order Or get search suggestion and latest updates.

Volker Fischer
Volker Fischer author of Program to print array element in reverse order is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!