Wednesday, 10 September 2014

// SORT THE ELEMENT IN  ASCENDING ORDER

#include<stdio.h>
#include<conio.h>
int main(void)
{
    int arr[10],i,j,n,temp,xchanges;
   
    printf("enter the element");
    scanf("%d",&n);
   
    for(i=0;i<n;i++)
    {
    printf("enter the element %d \n",i+1);
    scanf("%d",&arr[i]);
    }
   
    for(i=0;i<n-1;i++)
    {
                      xchanges=0;
           for(j=0;j<n-1-i;j++)
           {
                               if(arr[j]>arr[j+1])
                               {
                               temp=arr[j];
                               arr[j]=arr[j+1];
                               arr[j+1]=temp;
                               temp=0;
                               xchanges++;
                               }
                              
                              
           }
           if(xchanges==0)
                               break;
                     
    }
    printf("sort Ascending order is :-\n");
    for(i=0;i<n;i++)
    printf("%d ",arr[i]);
    printf("\n ");
    getch();
}


                                                               OUTPUT        



 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.