Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- int n=0;
- void display(int m[])
- {
- int i;
- printf("sorted form are :\n");
- for(i=0;i<n;i++)
- printf("%d,",m[i]);
- }
- main()
- {
- int i,j,t;
- char ch;
- int m[100];
- printf("* * * * * * * BUBBLE sort * * * * * * * * * *");
- printf("\n____________________________________________\n");
- while(1)
- {
- printf("do you want to enter data (y/n) :");fflush(stdin);
- ch=getche();
- if(ch=='n' || ch=='N') {break;}
- printf("\nenter the data : ");
- scanf("%d",&m[n]);
- n++;
- }
- printf("\n____________________________________________");
- printf("\n1> sort in ascending order\n2> sort in descending order");
- printf("\nenter your choice :");
- ch=getche();
- printf("\n____________________________________________");
- switch(ch)
- {
- case '1':
- printf("\nthe ascending order ");
- for(i=0;i<(n-1);i++)
- {
- for(j=0;j<((n-1)-i);j++)
- {
- if(m[j]>m[j+1])
- {
- t=m[j];
- m[j]=m[j+1];
- m[j+1]=t;
- }
- }
- }
- display(m);
- printf("\n____________________________________________");
- break;
- case '2':
- printf("\nthe descending order ");
- for(i=0;i<(n-1);i++)
- {
- for(j=0;j<((n-1)-i);j++)
- {
- if(m[j]<m[j+1])
- {
- t=m[j];
- m[j]=m[j+1];
- m[j+1]=t;
- }
- }
- }
- display(m);
- printf("\n____________________________________________");
- break;
- default:
- printf("\n*****invalid choice*****");
- }
- }
Add Comment
Please, Sign In to add comment