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 get_smallest(int *,int *,int);
- int main()
- {
- int index ,arr1[SIZE] = {3,5,0,-3,1,2,5,4,3,5};
- int arr2[SIZE] = {8,-3,18,2,3,4,33,4,2,5};
- print_arr(arr1,SIZE);
- print_arr(arr2,SIZE);
- sort_arr(arr1,SIZE);
- print_arr(arr1,SIZE);
- sort_arr(arr2,SIZE);
- print_arr(arr2,SIZE);
- index = get_smallest(arr1,arr2,SIZE);
- printf("smallest number in arr1, which doesnt coincide with number in arr2\n");
- printf("is %d, and its index is %d\n",arr1[index],index);
- 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;//value
- *el1 = *el2;
- *el2 = temp;
- }
- int get_smallest(int *a1,int *a2,int s)
- {
- int i,j,result,flag;
- for(i=0;i<s;i++)
- {
- flag = 0;
- for(j=0;j<s;j++)
- {
- if(a1[i]==a2[j])
- {
- flag =1;
- break;//exits for j
- }
- }
- if(flag ==0)
- break;//exits for i
- }
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement