Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- void bubble_sort( int tab[], int n)
- {
- int step;
- int temp;
- int i;
- for( step=0; step<n-1; ++step)
- for(i=0; i<n-step-1;++i)
- {
- if(tab[i]>tab[i+1])
- {
- temp = tab[i];
- tab[i]=tab[i+1];
- tab[i+1]= temp;
- }
- }
- }
- int main ()
- { int i;
- int tab[100];
- int n,step, temp;
- printf("\nEnter then natural number of elements to be sorted: \n ");
- scanf("%d", &n);
- for (i=0; i<n; i++)
- {
- printf("\nEnter the element : % d ", i+1);
- scanf( "%d" , &tab[i]); // not put space after d :>
- fflush(stdin);
- }
- for (i=0; i<n; i++)
- {
- bubble_sort(tab, n);
- printf("%d ", tab[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement