Wednesday, 10 September 2014

//C program to arrange or sort the array in the ascending order
#include<stdio.h>
#include<conio.h>
void main()
{
     int ar[100],j,n,i,tmp;
     
     printf(" Enter the size of the array \t");

     scanf("%d",&n);
     
     printf("Enter the elements in the array \t");
     for(i=0;i<n;i++)
     {
           scanf("%d",&ar[i]);
     }
     printf("\n Array is -");
     for(i=0;i<n;i++)
     {
           printf("\n5%d",ar[i]);
     }    
     for(i=0;i<n;i++)
     {
           for(j=0;j<n-i;j++)
           {
                 if(ar[j]>ar[j+1])
                 {
                       tmp=ar[j];

                       ar[j]=ar[j+1];

                       ar[j+1]=tmp;
                 }
           }
     }    
     printf("\nArray in the ascending order is-\n");
     for(i=0;i<n;i++)
     {
           printf("\n%d",ar[i]);
     }
     getch();
}

No comments:

Post a Comment

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