Program to reverse array


Prev Tutorial Next Tutorial

Program to reverse array elements

program to reverse array

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

 void main()
  {
   int a[20],b[20],i,j,n;
   clrscr();
   printf("How many elements you want to enter: ");
   scanf("%d",&n);
   printf("Enter any %d elements in Array: ",n);
   for(i=0; i<n ;i++)
   {
   scanf("%d",&a[i]);
   }
   printf("Reverse of Array: ");

   for(i=n-1,j=0; i>=0;i--,j++)
   {
    b[i]=a[j];
   }
   for(i=0; i<n ;i++)
   {
   printf("%d ",b[i]);
   }
  getch();
  }

Output

How many elements you want to enter: 5
Enter any 5 elements in Array: 
1 4 2 7 5
Reverse of Array: 5 7 2 4 1

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements