-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathg3.c
50 lines (47 loc) · 1.34 KB
/
g3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
void swap(int size,int *array1,int *array2);
//void swap(int size,int array1[],int array2[]);
int main(){
int i,j,size;
int array1[100],array2[100];
printf("Enter the size of first array ");
scanf("%d",&size);
printf("enter the elements of first array");
for(i=0;i<size;i++){
scanf("%d",&array1[i]);
}
printf("Enter the size of second array ");
scanf("%d",&size);
printf("Enter the elements of second array");
for(j=0;j<size;j++){
scanf("%d",&array2[j]);
}
swap(size,array1,array2);
printf("The first array after swapping is:");
for(i=0;i<size;i++){
printf("\n%d",array1[i]);
}
printf("The second array after swapping is:");
for(j=0;j<size;j++){
printf("\n%d",array2[j]);
}
}
/*void swap(int size,int array1[],int array2[]){
int i,temp;
for(i=0;i<size;i++){
temp=array1[i];
array1[i]=array2[i];
array2[i]=temp;
}
}*/
void swap(int size,int *array1,int *array2){
int *array1End = (array1 + (size-1));
int *array2End = (array2 + (size-1));
while(array1 <= array1End && array2 <= array2End){
*array1 ^= *array2;
*array2 ^= *array1;
*array1 ^= *array2;
array1++;
array2++;
}
}