to arrange number descending using bubble sort technique


/*to arrange number descending using bubble sort technique*/
#include<stdio.h>
#include<conio.h>
void main()
{
  int num[10];
  int loop,i;
  int last=10;
  int exchange;
  int temp;
 clrscr();

 printf("enter the 10 number\n");
 for(i=0;i<10;++i)
   scanf("%d",&num[i]);
for(loop=0;loop<9;++loop)
{
     exchange=0;
     for(i=0;i<(last-1);i++)
                 if(num[i]>num[i+1])
                    {
                      temp=num[i];
                      num[i]=num[i+1];
                      num[i+1]=temp;
                      exchange=exchange+1;
                    }
  if(exchange==0)
       break;
else
      last=(last-1);
 }
printf("number is in ascending order: \n");
for(i=0;i<10;i++)
     printf("%d\n",num[i]);
getch();
}

Enter the 10 number
88
0
14
1
6
9
6
94
52
22
Number is in descending order:
94
88
52
22
14
9
6
6
1
0
Related Posts Plugin for WordPress, Blogger...