Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 10
- //https://otvet.mail.ru/question/211049328
- void sort_arr(int *,int);
- void print_arr(int *,int);
- void swap_elements(int *,int *);
- int main()
- {
- int arr1[SIZE] = {3,5,7,-3,1,2,5,4,3,5};
- //int arr2[SIZE] = {8,-3,18,2,3,4,33,4,2,5};
- print_arr(arr1,SIZE);
- sort_arr(arr1,SIZE);
- print_arr(arr1,SIZE);
- return 0;
- }
- void print_arr(int *a1,int s)
- {
- int i;
- for(i=0;i<s;i++)
- {
- printf("%d\t",a1[i]);
- }
- printf("\n");
- }
- void sort_arr(int *a1,int s)
- {
- int i,j,t;
- for(i=0;i<s-1;i++)
- {
- printf("\ni is %d\n",i);
- for(j=i+1;j<s;j++)
- {
- printf("%d\t",j);
- if(a1[i] > a1[j])
- {
- swap_elements(&a1[i],&a1[j]);
- // t = a1[i]; //without swap()
- //a1[i] = a1[j];
- //a1[j] = t;
- }
- }
- }
- }
- void swap_elements(int *el1,int *el2)
- {
- int temp= *el1;//*el1
- *el1 = *el2;
- *el2 = temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement