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 */
- int main(int argc, char *argv[]) {
- int i ;
- int tab[100];
- int n,step, temp; // n elemnts need to be sorted
- printf(" Enter the natural number of elemnts to be sorted: ");
- scanf("%d", &n);
- for(i=0; i<n; ++i)
- {
- printf("%d Enter elemnt: ", i+1);
- scanf("%d", &tab[i]); //wybieram po kolei numery do sortowania
- }
- for( step=0; step<n-1; ++step)
- for(i=0; i<n-step-1;++i)
- {
- if(tab[i]>tab[i+1])
- {
- temp = tab[i]; //sortuje przez porównanie par
- tab[i]=tab[i+1];
- tab[i+1]= temp;
- }
- }
- printf("Sorted numbers: ");
- for(i = 0; i<n; ++i)
- printf("%d ", tab[i]); // drukowanie opowiedniej kolejności
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement