Wednesday, 6 August 2014

//SORTING
//CODE
#include<stdio.h>
#include<conio.h>
int main()
{
    int a[30],num,i,j,tmp=0;
    printf("\n Enter number of elements:");
    scanf("%d",&num);
    printf("\n Enter the numbers:");
    for(i=0;i<num;i++)
    {
        scanf("%d",&a[i]);
    }
for(i=0;i<num;i++)
{
  for(j=i+1;j<num;j++)
    {
           if(a[j]>a[j+1])
           {
              tmp=a[j];
              a[j]=a[j+1];
              a[j+1]=tmp;              
           }            
    }
}
    printf("\n the list is arranged in asending order");
    for(i=0;i<num;i++)
    {
        printf("\n %d",a[i]);              
    }
    getch();
    return 0;
}

//output
Enter number of elements3
 Enter the numbers
65
99
95
 the list is arranged in asending order
65
95
99


No comments:

Post a Comment

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