Showing posts with label PROGRAM TO SORT LIST OF NO. WITHOUT CHANGING THE ORIGINAL ARRAY. Show all posts
Showing posts with label PROGRAM TO SORT LIST OF NO. WITHOUT CHANGING THE ORIGINAL ARRAY. Show all posts

Saturday, June 16, 2012

64. PROGRAM TO SORT LIST OF NO. WITHOUT CHANGING THE ORIGINAL ARRAY


/*WAP TO SORT LIST OF NO. WITHOUT CHANGING THE ORIGINAL ARRAY.
 **************not workng***************/
 #include<conio.h>
 #include<stdio.h>
 void main()
 {
 int a[20],i,*ptr,j,temp,n;
 ptr=a;

 clrscr();
 printf("\n\nENTER THE SIZE OF THE ARRAY=");
 scanf("%d",&n);
 printf("\n\nENTER THE ELEMENTS=\n");
 for(i=0;i<n;i++)
 {
 scanf("%d",&a[i]);
 ptr[i]=&a[i];
 }
 for(j=0;j<n-1;j++)
 {
 for(i=0;i<n-1;i++)
  {
   if(*ptr[i]>*ptr[i+1])
   {
    temp=ptr[i];
    ptr[i]=ptr[i+1];
    ptr[i+1]=temp;
   }
  }}
 printf("\n\nORIGINAL ARRAY IS=");
 for(i=0;i<n;i++)
 printf("\n%d",a[i]);
 printf("\n\nAFTER SORTING ARRAY IS=");
 for(i=0;i<n;i++)
 printf("%d",*ptr[i]);
 getch();
 }

Programming the Whole World!