/*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();
}
No comments:
Post a Comment