Wednesday, 23 April 2014

14. Write an interactive program that will take as input a set of 20 integers and store them in an array and using a temporary array of equal length, reverse the order of the integers and display the values.



#include<stdio.h>
#include<conio.h>
void main()
{
          int arr[20],arr1[20],i,j=0;
          clrscr();
          //--------Input In First Array-------
          printf(" - Enter 20 Integers value to store in Array - \n\n");

          for(i=0; i<20; i++)
          {
                   printf("\t Enter value -> ");
                   scanf("%d",&arr[i]);
          }
          //-------For Reverse Order--------

          for(i=19; i>=0; i--)
          {
                   arr1[j]=arr[i];
                   j++;
          }
          getch();
          clrscr();
          //--------Print First Array------------

          printf("\n\n\t\tFirst Array Without Reverse");
          for(i=0; i<20; i++)
          {
                   printf("\n\t\t%d",arr[i]);
          }
          getch();
          clrscr();

          //-------Print Second Array-------------

          printf("\tArray In Reverse Order");
          for(i=0;i<19; i++)
          {
                   printf("\n\t\t%d",arr1[i]);
          }

          getch();
}

No comments:

Post a Comment