Wednesday, 6 August 2014

06-08-2014 sorting an array

#include<stdio.h>
#include<conio.h>
int main()
{
 int i,j,a,n,number[30];
 printf("enter the value of N \n");
 scanf("%d",&n);
 printf("enter the number \n");
 for(i=0;i<n;++i)
 scanf("%d",&number[i]);
 for(i=0;i<n;++i)
     {
      for(j=i+1;j<n;++j)
          {
           if(number[i]>number[j])
               {
                a=number[i];
                number[i]=number[j];
                number[j]=a;
                }
            }
      }            
printf("the number arranged in ascending order is given below \n");
for(i=0;i<n;++i)
printf("%d\n",number[i]);
getch();
}


                                       OUTPUT
enter the value of N
3
enter the number
5
9
3
the number arranged in ascending order is given below
3
5
9

1 comment:

  1. Which type of sort is it, bubble sort, selection sort or insertion sort.

    ReplyDelete

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