Saturday 1 November 2014

Write a program to accept 10 numbers and sort them with use of pointer.

No comments :
Write a program to accept 10 numbers and sort them with use of pointer.


PRO-21:
#include<stdio.h>
#include<conio.h>
void main()
{              int i,n,j,temp;
                int *ptr;
                clrscr();
                printf("\nEnter Limit : ");
                scanf("%d",&n);
                for(i=0;i<n;i++)
                {              scanf("%d",ptr+i);
                }
                printf("Sorted Element Are :\n");
                for(i=0;i<n;i++)
                {              for(j=i+1;j<n;j++)
                                {              if(*(ptr+i)>*(ptr+j))
                                                {              temp=*(ptr+i);
                                                                *(ptr+i)=*(ptr+j);
                                                                *(ptr+j)=temp;
                               }               }
                               
printf("  %d\n",*ptr+i);
                }
                getch();
}

OUTPUT:
Enter Limit : 4
Enter element : 14
15
11
12
Sorted Element Are :
  11
  12
  13

  14

No comments :

Post a Comment